In a grid, is there a way to get the number of rows returned by a Custom SQL?
Thanks,
Richard
Display number of rows returned by Custom SQL
-
- Profound User
- Posts: 40
- Joined: Mon Apr 26, 2010 11:53 am
- First Name: RICHARD
- Last Name: RUTA
- Company Name: WILLAM B. MEYER
- Phone: 203.984.7175
- Address 1: 255 LONG BEACH BLVD
- City: STRATFORD
- State / Province: Connecticut
- Zip / Postal Code: 06615
- Country: United States
- Contact:
-
- Experienced User
- Posts: 165
- Joined: Wed Dec 11, 2013 10:40 am
- First Name: Dave
- Last Name: Clark
- Company Name: WinWholesale, Inc.
- Phone: 937-294-5331
- Address 1: 31101 Kettering Blvd.
- City: Dayton
- State / Province: Outside Canada/USA
- Zip / Postal Code: 45439
- Country: United States
- Contact:
Re: Display number of rows returned by Custom SQL
If no other answer is forthcoming, you can at least use the following to find out the sequence number for the last data row in the grid. Note that "wob" is the name of one of our skins and, as such, you would change that to suit your need. The only issue would be when to call this. You may need to experiment a bit to find that out as I created this from a different working function and don't have any custom SQL situations with which I can test this. Good luck.
Code: Select all
/* ================================================================================
countNumberOfGridRows() returns the sequence number of the last data row for the
specified grid. The arguments are the grid id and name
of a bound field associated with a widget in that grid.
*/
wob.countNumberOfGridRows = function(gridId, boundFieldName)
{
var fld, seqno = 0, mygrid = getObj(gridId).grid; // get reference to grid object
if (mygrid) // if grid exists
{
while (fld = mygrid.getDataValue(seqno + 1, boundFieldName)) // loop on grid rows
{
++seqno; // increment row number
}
}
return seqno; // return last sequence no. to caller
}
- Alex
- Profound Logic Staff Member
- Posts: 233
- Joined: Fri Jan 04, 2008 12:10 pm
- First Name: Alex
- Last Name: Roytman
- Company Name: Profound Logic Software
- Contact:
Re: Display number of rows returned by Custom SQL
This will work for a grid that is populated by RPG code. However, it will not work for a database-driven grid populated by Custom SQL.
In our next update, we will add a JavaScript API that will return the total number of records in the grid, regardless of the grid type. However, the API can only be used once the grid has finished rendering. So, if you're trying to show the total number of records on the screen, this new API may not be the best fit. I would recommend having RPG code calculate the total number of records and output that value to the screen, instead.
In our next update, we will add a JavaScript API that will return the total number of records in the grid, regardless of the grid type. However, the API can only be used once the grid has finished rendering. So, if you're trying to show the total number of records on the screen, this new API may not be the best fit. I would recommend having RPG code calculate the total number of records and output that value to the screen, instead.
-
- Experienced User
- Posts: 165
- Joined: Wed Dec 11, 2013 10:40 am
- First Name: Dave
- Last Name: Clark
- Company Name: WinWholesale, Inc.
- Phone: 937-294-5331
- Address 1: 31101 Kettering Blvd.
- City: Dayton
- State / Province: Outside Canada/USA
- Zip / Postal Code: 45439
- Country: United States
- Contact:
Re: Display number of rows returned by Custom SQL
Is this because such a grid uses widgets that are bound directly to database columns and does not use widgets that are bound to RPG fields? If so, then that makes perfect sense. I guess I didn't make it real clear that the code I posted is for widgets bound to RPG fields. ;-) I did not stop to think about just what was meant by grids built via Custom SQL.Alex wrote:This will work for a grid that is populated by RPG code. However, it will not work for a database-driven grid populated by Custom SQL.
- Alex
- Profound Logic Staff Member
- Posts: 233
- Joined: Fri Jan 04, 2008 12:10 pm
- First Name: Alex
- Last Name: Roytman
- Company Name: Profound Logic Software
- Contact:
Re: Display number of rows returned by Custom SQL
Yes. First of all, the field name passed to the getDataValue() function has to be an RPG field name. Therefore, this function will not work with a data-bound grid.
But, secondly, with a data-bound grid, the server does not send the entire set of records to the client. Instead, the grid keeps fetching server data as the user scrolls through the grid. Internally, however, it does know the total record count, since it has to use it to render the scroll bar properly.
But, secondly, with a data-bound grid, the server does not send the entire set of records to the client. Instead, the grid keeps fetching server data as the user scrolls through the grid. Internally, however, it does know the total record count, since it has to use it to render the scroll bar properly.
-
- Experienced User
- Posts: 165
- Joined: Wed Dec 11, 2013 10:40 am
- First Name: Dave
- Last Name: Clark
- Company Name: WinWholesale, Inc.
- Phone: 937-294-5331
- Address 1: 31101 Kettering Blvd.
- City: Dayton
- State / Province: Outside Canada/USA
- Zip / Postal Code: 45439
- Country: United States
- Contact:
Re: Display number of rows returned by Custom SQL
It is also true of the code I posted that not only is it only for grid widgets bound to RPG fields; but, it will also only represent the total rows available when it is a load-all subfile. Cheers.
Who is online
Users browsing this forum: No registered users and 8 guests