Author Topic: Get individual check/ uncheck status of options  (Read 5122 times)

rsgmedia

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Get individual check/ uncheck status of options
« 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?
« Last Edit: July 03, 2017, 01:22:40 pm by paramquery »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6307
    • View Profile
Re: pqSelect with Paramquery Grid
« Reply #1 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 )

rsgmedia

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: pqSelect with Paramquery Grid
« Reply #2 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).

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6307
    • View Profile
Re: pqSelect with Paramquery Grid
« Reply #3 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/

rsgmedia

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Re: Get individual check/ uncheck status of options
« Reply #4 on: July 03, 2017, 02:53:36 pm »
Thanks!! :)