Page 1 of 1

Problem with looping through grid rows in Javascript.

Posted: Mon Apr 16, 2018 12:17 pm
by mwalter
I'm trying to loop through a grid and setting on a checkbox based upon a value in a checkbox in the header. Here is my code:

Code: Select all

debugger;
var myGrid = getObj('Grid1');
var myRows = myGrid.grid.getRecordCount();
//alert(myRows);
for (var x = 1;x <= myRows; x++) {
  var cbSelect = 'cbSel.';
  var cbObj = cbSelect + x;
  
  changeElementValue(cbObj,get("cbSelAll"));
}
cbSel is a checkbox in the grid. cbSelAll is a checkbox on the header.

The issue is that it only changes the values on the displayed rows. The others are left unchanged. I can watch it loop through the rows in the debugger in Chrome. Still, the others are not changed. Any Ideas?

Re: Problem with looping through grid rows in Javascript.

Posted: Mon Apr 16, 2018 1:18 pm
by Scott Klement
For performance reasons, the HTML elements for a grid are not created until you page the element onto the screen. Prior to that, the data is saved (under the covers) inside an array that we call the "data array". Unlike the get() API, the data array uses the BOUND field name (not the widget id) so you'll need to know which field is bound to the checkbox.

Once you know that, use the grid's built-in setDataValue() routine. This should work fine for all rows (assuming you are on a recent release of Profound UI).
http://www.profoundlogic.com/docs/pages ... d=26214527

The code would look something like this (untested)

Code: Select all

debugger;
var myGrid = getObj('Grid1');
var myRows = myGrid.grid.getRecordCount();
var newVal = get("cbSelAll");
//alert(myRows);
for (var x = 1;x <= myRows; x++) {
  myGrid.grid.setDataValue(x, "BOUND-FIELD-NAME-HERE", newVal);
}

Re: Problem with looping through grid rows in Javascript.

Posted: Mon Apr 16, 2018 2:52 pm
by mwalter
PERFECT! ! !

Thanks, Scott. AGAIN! !