ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: mikep on September 20, 2021, 04:17:23 pm
-
I'm iterating the grid rows and updating the row, if it is currently selected.
-How do I determine if the row is currently selected?
-Is below the best way to iterate/update specific rows in the grid?
var data = $gridMain.pqGrid('getData');
for (i = 0; i < data.length; i++) {
if ( //how to determine if row is selected??) {
$gridMain.pqGrid('updateRow', { checkEditable: false, rowIndx: i, row: { [key]:newvalue } });
}
}
-
Assuming selectionModel.type = 'row', selected rows have pq_rowselect property set to true.
BTW it's not good to call updateRow in a loop for performance reasons, rather rowList could be prepared in a loop and updateRow method be called once.
https://paramquery.com/pro/api#method-updateRow (update multiple rows at once.)
-
Thanks, Are you able to update the example below to show this?
https://jsfiddle.net/yn1km54b/
-
Please give it a try and let me know if you face any difficulty.
selectionModel: {type: 'row'}
if( data[i].pq_rowselect ){ //row is selected.
//construct the rowList.
}
Multiple rows update at once example is there in the API:
https://paramquery.com/pro/api#method-updateRow
-
Thanks. I need to understand how to construct the rowList based on the data index. The updateRow is not updating the correct row for me when when I have the grid grouped, so seeing a working example in the JSFiddle file I sent would help me.
-
No problem, please check this: https://jsfiddle.net/ntkmosa3/
I've used grid SelectRow API to get selected rows.
https://paramquery.com/pro/api#method-SelectRow
-
Thanks! If I want to iterate all rows and not just the selected rows, how would this line change?
var allRows= grid.SelectRow().getSelection();
-
var allRows= grid.pageData();
-
Changing the selectionModel to { type: 'row' }, doesn't help because I need the cell drag and fill, copy and paste, and delete capability. Can you update the function 'UpdateSelectedRows' in the example below, if the selectionModel is not 'row'?
https://jsfiddle.net/ntkmosa3/
-
In that case, we can use eachRow method of Selection object.
grid.Selection().eachRow(function(rowData, rowIndx){
rowList.push({
rowIndx: rowIndx,
newRow: {company: 'ABC'}
})
})
https://jsfiddle.net/p0qn3x6o/
-
Any idea why I get this error? Code seems identical to this example. https://jsfiddle.net/h02gs4Lk/
-
https://paramquery.com/pro/api#method-Range
API states that eachRow method is available since v8.0.0
-
Thanks for quick reply. It works great!
I'm updating all my code to account for this.
-what's the best way to get a count of selected rows now? (I'm creating a counter and iterating the foreach, not sure if there's a better way.)
-what the best way to reference the selected row, if the count is 1. (I'm using the foreaach, even though only 1 record, not sure if there's a better way)
--new code
var selCount = 0;
grid.Selection().eachRow(function (rowData, rowIndx) {
selCount += 1;
})
--old code
var grid = $gridMain.pqGrid('instance');
var selection = grid.SelectRow().getSelection();
if (selection.length > 1) {
showNotify("Only 1 row in the grid can be selected.");
}
else if (selection.length == 1) {
DoAction(selection[0].rowData)
}
-
1. It's correct to count the no of selected rows.
2.
grid.Selection().eachRow(function (rowData, rowIndx) {
//rowData is reference to each selected row.
})