Problem with looping through grid rows in Javascript.

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
mwalter
Experienced User
Posts: 140
Joined: Wed Sep 14, 2016 2:58 pm
First Name: Mark
Last Name: Walter
Company Name: Paragon Consulting Services
Contact:

Problem with looping through grid rows in Javascript.

Post 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?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Problem with looping through grid rows in Javascript.

Post 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);
}
mwalter
Experienced User
Posts: 140
Joined: Wed Sep 14, 2016 2:58 pm
First Name: Mark
Last Name: Walter
Company Name: Paragon Consulting Services
Contact:

Re: Problem with looping through grid rows in Javascript.

Post by mwalter »

PERFECT! ! !

Thanks, Scott. AGAIN! !
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests