Page 1 of 1

Reading a subfile grid with filtering turn on

Posted: Fri Apr 28, 2017 10:44 am
by randyh
After loading a subfile grid with records, a user will right click on the header and filter a column. What's displayed on the page is correct (based on filter) and I can export the grid data to excel, listing only the filter records, but is there a trick into reading the grid data (within my RGPle program) and only processing the filtered records on the page?

Re: Reading a subfile grid with filtering turn on

Posted: Fri Apr 28, 2017 12:10 pm
by Scott Klement
You would have to code something to make it work. You would have to loop thru and determine which rows are filtered in Javascript, then somehow send that info back to the RPG program.

One way would be to put a hidden field in the subfile and set that from JavsaScript. Then the RPG could read all of the records but ignore the ones where the hidden field was not set by JS to indicate that the row was filtered.

Re: Reading a subfile grid with filtering turn on

Posted: Fri Apr 28, 2017 1:43 pm
by randyh
Within my Grid1, I added a hidden field name OPT

Which event trigger would I use for this javascript?

var myGrid = getObj("Grid1");
for (var r=0; r<myGrid.grid.getRecordCount(); r++) {
if (!myGrid.grid.isRowFilteredOut(r)) {
myGrid.grid.setDataValue(r, "OPT", "1");
}
}

I've tried OnfilterChange of the grid and Onsubmit of record format, but the hidden OPT field did not change.

Re: Reading a subfile grid with filtering turn on

Posted: Fri Apr 28, 2017 3:33 pm
by shuffman
Randy,

I've used that exact same code in the OnfilterChange event and it has worked for me. I would double check your grid/field naming. Based on the JavaScript you posted you may need to change some of the following: "Grid1" has to be the ID property of the grid and "OPT" has the be the bound variable name of the hidden field.

var myGrid = getObj("Grid1");
for (var r=0; r<myGrid.grid.getRecordCount(); r++) {
if (!myGrid.grid.isRowFilteredOut(r)) {
myGrid.grid.setDataValue(r, "OPT", "1");
}
}

Sam

Re: Reading a subfile grid with filtering turn on

Posted: Fri Apr 28, 2017 3:34 pm
by Scott Klement
onsubmit is too late.... the data to be sent to the server has already been gathered by that point. But, onfilterchange should work.

Make sure your hidden field is input-capable (i.e. a textbox with visibility = hidden). An output field won't work because they are never sent back to RPG, being output only.