Identifying row in a grid by the way the user sorts in RPG
-
- Profound User
- Posts: 42
- Joined: Wed Jun 14, 2017 12:06 pm
- First Name: Dan
- Last Name: Devoe
- Company Name: Boston Warehouse Trading
- State / Province: Massachusetts
- Zip / Postal Code: 02062
- Country: United States
- Contact:
Identifying row in a grid by the way the user sorts in RPG
I have a Rich Display that staff in our warehouse uses to create ASNs (EDI Advance Ship notifications) & corresponding carton labels.
I'm running into an issue where when the users sort the data in the grid in a certain way, they expect the output for the ASN labels to be created in the same fashion.
Ideally before the customer hits the button to return control back to the RPG program for processing, I'd like to read thru the grid in the order that it is displayed to the user & populate a hidden field in each row of the grid to store the corresponding grid line number (similar to RRN - only in the order that the user sees the data).
Then in the back-end, I would use this hidden value to output the labels in the order that the user sees them.
I was wondering if anyone had a js example of reading thru a grid in the order that it is sorted on the screen.
Thanks
I'm running into an issue where when the users sort the data in the grid in a certain way, they expect the output for the ASN labels to be created in the same fashion.
Ideally before the customer hits the button to return control back to the RPG program for processing, I'd like to read thru the grid in the order that it is displayed to the user & populate a hidden field in each row of the grid to store the corresponding grid line number (similar to RRN - only in the order that the user sees the data).
Then in the back-end, I would use this hidden value to output the labels in the order that the user sees them.
I was wondering if anyone had a js example of reading thru a grid in the order that it is sorted on the screen.
Thanks
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Identifying row in a grid by the way the user sorts in RPG
Someone correct my JavaScript here but try something like this:
====================
var data = getObj("your_grid");
var gridrec = data.grid.getRecordCount();
for (var i=1; i < gridrec + 1; i++) {
data.grid.setDataValue(i, "your_hidden_field", i);
}
====================
var "i" should equal the row number and that would be what you place in your hidden field.
Someone please correct me if I'm leading Dan astray!!!!
====================
var data = getObj("your_grid");
var gridrec = data.grid.getRecordCount();
for (var i=1; i < gridrec + 1; i++) {
data.grid.setDataValue(i, "your_hidden_field", i);
}
====================
var "i" should equal the row number and that would be what you place in your hidden field.
Someone please correct me if I'm leading Dan astray!!!!
-
- 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: Identifying row in a grid by the way the user sorts in RPG
Eric's answer makes sense. I didn't test it, though.
-
- Profound User
- Posts: 42
- Joined: Wed Jun 14, 2017 12:06 pm
- First Name: Dan
- Last Name: Devoe
- Company Name: Boston Warehouse Trading
- State / Province: Massachusetts
- Zip / Postal Code: 02062
- Country: United States
- Contact:
Re: Identifying row in a grid by the way the user sorts in RPG
Thank you Eric & Scott.
I was thinking more about this & was thinking that I could utilize the grid's rowNumber functionality/keyword that ProfoundUI has as part of the loop.
However, the solution that Eric came up with seems more straight-forward.
I'll let you know if I encounter any issues.
-Dan
I was thinking more about this & was thinking that I could utilize the grid's rowNumber functionality/keyword that ProfoundUI has as part of the loop.
However, the solution that Eric came up with seems more straight-forward.
I'll let you know if I encounter any issues.
-Dan
-
- Profound User
- Posts: 42
- Joined: Wed Jun 14, 2017 12:06 pm
- First Name: Dan
- Last Name: Devoe
- Company Name: Boston Warehouse Trading
- State / Province: Massachusetts
- Zip / Postal Code: 02062
- Country: United States
- Contact:
Re: Identifying row in a grid by the way the user sorts in RPG
I may be having a denser-than-normal moment - I'm stumped & am hoping that someone can find an error in my logic.
My grid has an ID of s1_items
One of the fields within the grid has the following properties:
id: s1_sortedRow
widget type: textbox
value: s1_sortrow (bound as a data type decimal with length of 5, 0)
I cannot get the s1_sortrow to be passed back to the RPG. I was debugging the program in RPG & always receiving a 0 for each s1_sortrow when I was watching the variable. Then I realized that I wasn't actually using the variable within the program & perhaps the program was compiled not to show unreferenced data items. Added dsply s1_sortrow;
Problem still persists.
I tried this as Eric originally referenced & then slightly redid it - same results.
This is my on-click event (pui.click is referenced because there is a variable in the response field)
I then seemed to remember that the variable name may need to be referenced in upper case - so tried this:
I'm sure that I'm missing something obvious - just hoping that a second set of eyes can see it.
Thanks
-Dan
My grid has an ID of s1_items
One of the fields within the grid has the following properties:
id: s1_sortedRow
widget type: textbox
value: s1_sortrow (bound as a data type decimal with length of 5, 0)
I cannot get the s1_sortrow to be passed back to the RPG. I was debugging the program in RPG & always receiving a 0 for each s1_sortrow when I was watching the variable. Then I realized that I wasn't actually using the variable within the program & perhaps the program was compiled not to show unreferenced data items. Added dsply s1_sortrow;
Problem still persists.
I tried this as Eric originally referenced & then slightly redid it - same results.
This is my on-click event (pui.click is referenced because there is a variable in the response field)
Code: Select all
console.log('Here');
setTimeout(function() {
var myGrid = getObj("s1_items");
var gridrec = myGrid.grid.getRecordCount();
for (var i=1;i<=gridrec;i++) {
console.log(i);
myGrid.grid.setDataValue(i, "s1_sortrow", i);
}
},20);
pui.click(this,true);
Code: Select all
console.log('Here');
setTimeout(function() {
var myGrid = getObj("s1_items");
var gridrec = myGrid.grid.getRecordCount();
for (var i=1;i<=gridrec;i++) {
console.log(i);
myGrid.grid.setDataValue(i, "S1_SORTROW", i);
}
},20);
pui.click(this,true);
Thanks
-Dan
-
- 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: Identifying row in a grid by the way the user sorts in RPG
It is not valid to have both an 'onclick' event and also have a variable bound to the response property. You can't do both on the same button.
Instead, you should consider having a separate (hidden) button with the response property bound, and use pui.click() to click that separate button when you're done with your onclick event.
Another problem with your code is that you're running the grid row stuff in a timeout. That means its going to run AFTER the pui.click(), which means the values are unlikely to be sent to the server. (Or best case scenario, it becomes a 'race condition' where its a race to see whether the timeout or the pui.click completes first, possibly resulting in only some of the values being set before the screen is submitted... which wouldn't be good, either.)
Can you explain why this is in a timeout?
Instead, you should consider having a separate (hidden) button with the response property bound, and use pui.click() to click that separate button when you're done with your onclick event.
Another problem with your code is that you're running the grid row stuff in a timeout. That means its going to run AFTER the pui.click(), which means the values are unlikely to be sent to the server. (Or best case scenario, it becomes a 'race condition' where its a race to see whether the timeout or the pui.click completes first, possibly resulting in only some of the values being set before the screen is submitted... which wouldn't be good, either.)
Can you explain why this is in a timeout?
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Identifying row in a grid by the way the user sorts in RPG
Dan,
Your element name in the setDataValue needs to match exactly as it is defined in the "id" entry in the properties.
Your element name in the setDataValue needs to match exactly as it is defined in the "id" entry in the properties.
-
- 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: Identifying row in a grid by the way the user sorts in RPG
Eric,
grid.setDataValue() takes a bound field name (not an element name or "id" property) as its parameter. The setDataValue() API will automatically convert whatever you pass to uppercase for you, so its not required that you type the parameter in all uppercase.
https://docs.profoundlogic.com/x/fwCQAQ
The part that corresponds to the 'id' property is the part that's passed to getObj() -- and you're right that it is case-sensitive and must match exactly.
grid.setDataValue() takes a bound field name (not an element name or "id" property) as its parameter. The setDataValue() API will automatically convert whatever you pass to uppercase for you, so its not required that you type the parameter in all uppercase.
https://docs.profoundlogic.com/x/fwCQAQ
The part that corresponds to the 'id' property is the part that's passed to getObj() -- and you're right that it is case-sensitive and must match exactly.
-
- Experienced User
- Posts: 116
- Joined: Wed Sep 05, 2012 11:14 am
- First Name: Eric
- Last Name: Hill
- Company Name: Integrated Corporate Solutions
- Phone: 256-760-8239
- Address 1: 501 S Wood Avenue
- City: Florence
- State / Province: Alabama
- Zip / Postal Code: 35630
- Country: United States
- Contact:
Re: Identifying row in a grid by the way the user sorts in RPG
Thanks for the clarification, Scott!!!!
-
- Profound User
- Posts: 42
- Joined: Wed Jun 14, 2017 12:06 pm
- First Name: Dan
- Last Name: Devoe
- Company Name: Boston Warehouse Trading
- State / Province: Massachusetts
- Zip / Postal Code: 02062
- Country: United States
- Contact:
Re: Identifying row in a grid by the way the user sorts in RPG
Yes - ignorance on my part... :-) There have been numerous occasions where I had unexpected results when working with grids. More often than not, when I sent the suspect code in question to support, I was instructed to put it in a timeout.Another problem with your code is that you're running the grid row stuff in a timeout.
Can you explain why this is in a timeout?
In this case, when running my program thru debug when testing the js that Eric provided, my variable wasn't getting populated in the RPG. So I thought that I'd try a timeout.
It turns out that the issue I was experiencing did indeed have to do with the s1_sortrow being unreferenced in the program. When I removed the timeout & added in dsply s1_sortrow; into the program, I now get the desired results (as opposed to simply setting a breakpoint & doing an eval on s1_sortrow, which because it wasn't referenced, showed 0). Had I realized this initially, I wouldn't have added the timeout.I cannot get the s1_sortrow to be passed back to the RPG. I was debugging the program in RPG & always receiving a 0 for each s1_sortrow when I was watching the variable. Then I realized that I wasn't actually using the variable within the program & perhaps the program was compiled not to show unreferenced data items.
So problem seems to be resolved. Thank you again Eric & Scott - sorry for wasting your time with an error on my part.
And as an aside,
Just wanted to make you aware that I've done this with a few of my screens in the past - and by following the logic in documentation, it seems to work appropriately. If both response & onclick defined, onclick takes precedence & response ignored by default. Passing true as an optional parameter within pui.click causes the response to be triggered & ignores the onclick. Therefore, passing pui.click(this, true) will force the response to run instead of the onclick - so when run within the onclick, it works.It is not valid to have both an 'onclick' event and also have a variable bound to the response property. You can't do both on the same button.
https://docs.profoundlogic.com/pages/vi ... Id=3276856
Thank you again for your assistance.
-Dan
Who is online
Users browsing this forum: Bing [Bot] and 0 guests