Number of Grid Rows Selected

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
DaveLClarkI
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:

Number of Grid Rows Selected

Post 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;
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

Re: Number of Grid Rows Selected

Post 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.
DaveLClarkI
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: Number of Grid Rows Selected

Post 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
}
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

Re: Number of Grid Rows Selected

Post 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.
DaveLClarkI
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: Number of Grid Rows Selected

Post by DaveLClarkI »

David wrote:We can consider adding one.
Would much appreciate it. Thanks.
User avatar
David
Profound Logic Staff Member
Posts: 690
Joined: Fri Jan 04, 2008 12:11 pm
First Name: David
Last Name: Russo
Company Name: Profound Logic Software
Contact:

Re: Number of Grid Rows Selected

Post by David »

Done -- added for next release "getSelectedCount()" method on the grid.

We're planning release for next week.
DaveLClarkI
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: Number of Grid Rows Selected

Post by DaveLClarkI »

Thanks very much.
Bruno97
Profound User
Posts: 61
Joined: Wed Jul 16, 2014 8:35 am
First Name: BRUNO
Last Name: HAJJAR
Company Name: APLUS INFORMATIQUE
Phone: 0664771058
Address 1: 9 AVENUE HENRI MATISSE
Address 2: IMMEUBLE MATISSE
City: NICE
Zip / Postal Code: 06200
Country: France
Contact:

Re: Number of Grid Rows Selected

Post by Bruno97 »

Hi,

Could you please add this API to the online documentation ?

Thanks,
Bruno
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests