ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: Syreta on June 25, 2018, 12:33:20 pm

Title: Check/Uncheck Checkbox in cellRightClick Event
Post by: Syreta 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
Title: Re: Check/Uncheck Checkbox in cellRightClick Event
Post by: paramvir 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
Title: Re: Check/Uncheck Checkbox in cellRightClick Event
Post by: Syreta 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?
Title: Re: Check/Uncheck Checkbox in cellRightClick Event
Post by: paramvir 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.
},
Title: Re: Check/Uncheck Checkbox in cellRightClick Event
Post by: paramvir 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.
},