onRowClick and getSelectedRows

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
ndeppe
New User
Posts: 14
Joined: Fri Dec 05, 2014 1:17 pm
First Name: Nick
Last Name: Deppe
Company Name: Victaulic
Phone: 6109233257
Address 1: 4901 Kesslersville Road
City: Easton
State / Province: Pennsylvania
Zip / Postal Code: 18040
Country: United States
Contact:

onRowClick and getSelectedRows

Post by ndeppe »

We have an application in which users can select multiple rows, and the screen displays a sum of values from the selected rows. I figured the best way to do this is to put a code in the grid's onRowClick event that would use getSelectedRows() to get a list of all rows that are selected, then get the value from each row returned in the array to get the sum of the values. The problem is it seems like the the onRowClick event is firing before the row selection property is being set. So when the code executes in onRowClick, the result of getSelectedRow() is the selected rows before I make the selection, and not after.

Is there a better way to determine what rows are selected when a user makes a selection?
Scott Klement
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: onRowClick and getSelectedRows

Post by Scott Klement »

I've never done this, so not sure what to tell you.

I have done something similar with the grid's filter feature. There, the user can select rows by changing the filter string, and the grid has an "onfilterchange" event that runs whenever the filter changes, this way you can update the totals whenever it changes, which is really convenient. Would that work for you?

I haven't done this with row selection, exactly. I've done similar-ish things by having the user click a button to get the results (in my case, it wasn't a total, but it could've been) or by using the right-click (context) menu to do things based on row selection. These also worked fine. So you could consider these alternatives as well.

But, never tried to do it when the selection is clicked.
User avatar
Megan
Profound Logic Staff Member
Posts: 90
Joined: Mon Sep 11, 2017 12:15 pm
First Name: Megan
Last Name: Bond
Company Name: Profound Logic
Phone: 5623227473
State / Province: California
Zip / Postal Code: 92692
Country: United States
Contact:

Re: onRowClick and getSelectedRows

Post by Megan »

Hello Nick,

I have looked into this further and have a solution that may work for you. I used the following code on the onrowclick event of the grid:

Code: Select all

setTimeout(function() {
  var myGrid = getObj("Grid1");
  var myArray = myGrid.grid.getSelectedRows(); 
  
  var totalInts = 0;
  var totalDecs = 0;
  var totalMnys = 0;
  
  for (var i=0; i<myArray.length; i++) {
    
    var rrn = myArray[i];
 
    totalInts += parseInt(get("Ints." + rrn),10);
    totalDecs += parseFloat(get("Decs." + rrn));
    totalMnys += parseFloat(get("Monies." + rrn));
    
  }
  
  applyProperty("TotalInts", "value", totalInts);
  applyProperty("TotalDecs", "value", totalDecs.toFixed(5));
  applyProperty("TotalMnys", "value", totalMnys.toFixed(2));
  
}, 10);
The timeout function gives the program a chance to finish updating the selected rows list, which is then available to be used to get the values from the cells and add them up. You may need to change the time value of the timeout function in order for the selected rows list to have enough time to update. I used '+=' to add up the values in the for loop. I then applied the value property with the new calculated value.

Result:
totalonrowclick.gif
totalonrowclick.gif (1007.53 KiB) Viewed 790 times
I hope this helps!
~MEGAN BOND
Technical Support Specialist
support@profoundlogic.com
ndeppe
New User
Posts: 14
Joined: Fri Dec 05, 2014 1:17 pm
First Name: Nick
Last Name: Deppe
Company Name: Victaulic
Phone: 6109233257
Address 1: 4901 Kesslersville Road
City: Easton
State / Province: Pennsylvania
Zip / Postal Code: 18040
Country: United States
Contact:

Re: onRowClick and getSelectedRows

Post by ndeppe »

Hi Megan,

This solution worked for me, although I'm not too fond of using a timeout in a situation like this. I'm just not sure if there is a guarantee of the row selection property being updated within 10 milliseconds of the onRowClick event. This solution does seem to be working for me though and I haven't been able to break it.

Perhaps in the future a new event can be added when a user makes a selection on a grid, like onRowSelected for example. The event would fire after the selection property is set on the row. Does that make sense? I could submit an RFE for this.
User avatar
Megan
Profound Logic Staff Member
Posts: 90
Joined: Mon Sep 11, 2017 12:15 pm
First Name: Megan
Last Name: Bond
Company Name: Profound Logic
Phone: 5623227473
State / Province: California
Zip / Postal Code: 92692
Country: United States
Contact:

Re: onRowClick and getSelectedRows

Post by Megan »

Hello Nick,

I'm glad to hear my solution worked for you! I also completely understand your desire to have a onRowSelected event. If you would like this event submitted as a feature request, could you please send us an email at support@profoundlogic.com with a general description of how you would like the onRowSelected function (i.e. row number should be passed to the event) and how important this feature is for you. This information will help our developers in assessing the necessity of the feature and the urgency of the feature to be implemented if accepted.

Thanks,
~MEGAN BOND
Technical Support Specialist
support@profoundlogic.com
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests