ParamQuery grid support forum

General Category => Help for ParamQuery Select => Topic started by: rsgmedia on July 03, 2017, 10:59:13 am

Title: Get individual check/ uncheck status of options
Post by: rsgmedia on July 03, 2017, 10:59:13 am
We are using pqSelect (multiselect using checkbox) in paramquery grid.
What we need is checkbox change event of pqSelect here. Is there any option to achieve this?
Title: Re: pqSelect with Paramquery Grid
Post by: paramvir on July 03, 2017, 11:06:00 am
There is change event whenever checkbox is selected / unselected.

https://paramquery.com/select (2nd example of multiple select )
Title: Re: pqSelect with Paramquery Grid
Post by: rsgmedia on July 03, 2017, 12:31:49 pm
Thanks. event is firing and I am able to get all selected options using this but when change event is fired on check/uncheck of any option I am not able to get that option. (given that options of this list are not having unique values).
Title: Re: pqSelect with Paramquery Grid
Post by: paramvir on July 03, 2017, 01:12:45 pm
Ok, so you mean to get individual checked / unchecked options rather than complete list of selected options in every change event.

That can be done by calculating difference between old and new set of selected options. Please open your browser's console to see the output.

Code: [Select]
//initialize the pqSelect widget.
$("#select1").pqSelect({
    multiplePlaceholder: 'Select Countries',   
    checkbox: true //adds checkbox to options   
}).on("change", function(){
//save initial value.
var oldVal = $("#select1").val() || [];
return function( evt ){
var newVal = $(this).val() || [],
diff, state;
//console.log(oldVal);
//console.log(newVal);
if(oldVal.length > newVal.length){
state = "unchecked";
diff = $(oldVal).not(newVal).get();
}
else{
state = "checked";
diff = $(newVal).not(oldVal).get();
}
console.log("diff: ", diff, " state: ", state);

oldVal = newVal;
}
}()).pqSelect( 'open' );

http://jsfiddle.net/dLvx6u63/66/
Title: Re: Get individual check/ uncheck status of options
Post by: rsgmedia on July 03, 2017, 02:53:36 pm
Thanks!! :)