Page 1 of 1
Number of Grid Rows Selected
Posted: Thu Aug 07, 2014 1:33 pm
by DaveLClarkI
For the Profound UI Grid object, is there now a one-liner type of equivalent to the following DOM method for determining the number of current selections for a multiple-select list box?
Code: Select all
var count = htmlElement.querySelectorAll("option:checked").length;
Re: Number of Grid Rows Selected
Posted: Tue Aug 19, 2014 11:53 am
by David
This approach may not work so well, due to details of the Grid widget implementation:
1. The Grid widget only renders the number of rows defined in the "number of rows" property. So, if you load more records than that into your subfile, Profound UI does not render more rows into the DOM. It simply changes the data that is displayed in the same rows as you scroll through all your records. So, this type of thing could work in the situation where you are never loading more records into the subfile than "number of rows".
2. Even in the case of a subfile where the record count will never exceed "number of rows", this approach is further complicated by the fact that the Grid rendering does not produce any element that corresponds to a "row". It just renders a bunch of divs that correspond to "cells", and these are rendered at top-level, with no containing "row" element. The rendering does put a "selected" CSS class on the cell divs when selected.
Profound UI does put a 'selected' CSS class on So, you can do something like this (untested):
Code: Select all
var count = document.getElementById("GridId").querySelectorAll("div.selected").length / numberOfGridColumns;
To get the selected row count reliably for any type of subfile loading, you should be able to use this API to check the bound 'selection field' value:
http://www.profoundlogic.com/docs/displ ... ldName+%29
You can call that in a loop by starting at row 1 and incrementing as you go, along with the 'selection field' name. Quit when the API returns null field value.
Re: Number of Grid Rows Selected
Posted: Tue Aug 19, 2014 12:45 pm
by DaveLClarkI
David wrote:This approach may not work so well, due to details of the Grid widget implementation ...
I'm aware of everything you pointed out and I guess I just didn't make myself clear as to what I was asking. I didn't actually want to use the querySelectorAll() method. I was just using that as a native JavaScript example of a one-line method for obtaining the desired information -- i.e., without having to perform my own loop. So, what I was asking is whether Profound has come up with an API for obtaining that information?
David wrote:To get the selected row count reliably for any type of subfile loading, you should be able to use this API to check the bound 'selection field' value:
http://www.profoundlogic.com/docs/displ ... ldName+%29
You can call that in a loop by starting at row 1 and incrementing as you go, along with the 'selection field' name. Quit when the API returns null field value.
Yes, I already have my own code using that method but don't like having to do this. Would much rather have an API for it.
Code: Select all
/* ================================================================================
countGridRowSelections() returns a count of the number of grid rows currently
selected. The arguments are the grid id and name of
the bound indicator (0/1) type "selection field"
associated with that grid.
*/
wob.countGridRowSelections = function(gridId, selectionFieldName)
{
var mygrid = getObj(gridId).grid, // get reference to grid object
cnt = 0, sel, seqno = 1; // initialize variables
if (mygrid) // if grid exists
{
while (sel = mygrid.getDataValue(seqno, selectionFieldName)) // loop on grid rows
{
if (sel == "1") // if row is selected
{
++cnt; // increment selection count
}
++seqno; // increment row number
}
}
return cnt; // return selection count to caller
}
Re: Number of Grid Rows Selected
Posted: Tue Aug 19, 2014 12:56 pm
by David
I see. No, we don't have an API that does this. I guess the advantage that would give you is that it could work out internally what is the "selection field" name and also the "selection value". We can consider adding one.
Re: Number of Grid Rows Selected
Posted: Tue Aug 19, 2014 1:20 pm
by DaveLClarkI
David wrote:We can consider adding one.
Would much appreciate it. Thanks.
Re: Number of Grid Rows Selected
Posted: Tue Aug 19, 2014 6:24 pm
by David
Done -- added for next release "getSelectedCount()" method on the grid.
We're planning release for next week.
Re: Number of Grid Rows Selected
Posted: Tue Aug 19, 2014 11:03 pm
by DaveLClarkI
Thanks very much.
Re: Number of Grid Rows Selected
Posted: Thu Mar 05, 2015 5:37 am
by Bruno97
Hi,
Could you please add this API to the online documentation ?
Thanks,
Bruno