Author Topic: Check/Uncheck Checkbox in cellRightClick Event  (Read 3139 times)

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Check/Uncheck Checkbox in cellRightClick Event
« on: June 25, 2018, 12:33:20 pm »
Hello,

how can I check/uncheck a checkbox within the cellRightClick event?
I tried to update ui.rowData.#checkboxDataIndx# to "true" or "false" and refresh the grid. This works, but the row is not highlighted (like regular check) and when I right click another cell after first cellRightClick, it doesn't work any more.

Is there a correct way to do this?

Thanks,
Syreta

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Check/Uncheck Checkbox in cellRightClick Event
« Reply #1 on: June 25, 2018, 10:30:42 pm »
Checkbox can be checked programmatically by updatRow() method.

Please try this code

Code: [Select]
cellRightClick: function(evt, ui){
//debugger;
this.updateRow({
newRow:{state: true},
rowIndx: ui.rowIndx
})
return false; //prevent opening of browser context menu.
},

in this demo

https://paramquery.com/pro/demos/selection_checkbox
« Last Edit: June 25, 2018, 10:51:12 pm by paramquery »

Syreta

  • Pro Ultimate
  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Check/Uncheck Checkbox in cellRightClick Event
« Reply #2 on: June 26, 2018, 12:13:26 pm »
Thanks for your answer, this works for me! :)
When I update the checkbox of the current row with this code, I want to uncheck all other checkboxes. For this, I found the following code:

Code: [Select]
$("#grid_table").pqGrid("setSelection", null);
Is it the correct way to do this before updating the current row or is there a better way?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Check/Uncheck Checkbox in cellRightClick Event
« Reply #3 on: June 26, 2018, 05:08:07 pm »
Iterate over all rows and set state: true for current row and state: false for other rows

Code: [Select]
cellRightClick: function(evt, ui){
//debugger;
var rowList = this.option('dataModel.data').map(function(rd, indx){
return {
newRow:{state: (ui.rowData == rd)},
rowIndx: indx
}
})

this.updateRow({ rowList: rowList });

return false; //prevent opening of browser context menu.
},
« Last Edit: June 26, 2018, 05:46:55 pm by paramquery »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Check/Uncheck Checkbox in cellRightClick Event
« Reply #4 on: June 26, 2018, 05:42:47 pm »
setSelection also works fine.

Code: [Select]
cellRightClick: function(evt, ui){
//debugger;
this.setSelection(null);
this.setSelection({rowIndx: ui.rowIndx}); //select current row.
return false; //prevent opening of browser context menu.
},