cancel
Showing results for 
Search instead for 
Did you mean: 

Counting selected rows in table

Former Member
0 Kudos

Heya,

I want quite simple to count the selected rows in my table....i looked in the forum and found a quite simple piece of code which would enable this:


int count = 0;
		for (int j = 0, n = wdContext.nodeTask().size(); j < n; ++j) {
			if (wdContext.nodeTask().getLeadSelection() == j
				|| wdContext.nodeTask().isMultiSelected(j)) {
				count++;
			}
		}

Looks quite simple but when i select multiple rows in my table....1 lead selection and 2 extra...the count still shows 1. I do count in the wdDoModifyView. Can anyone tell me why this aint working?

much thanks,

Hugo

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try this please, i think this will do the trick (not tried out)

int count = 0;

for (int i = 0, i<wdContext.nodeTask().size(); i++) {

if (wdContext.nodeTask().isSelected(i) {

count++;

}

}

wdComponentAPI.getMessageManager().reportSuccess("Count is: " +count);

Former Member
0 Kudos

Thx for the quick response.

Table is bound to the taskNode and is set to multiple....also tried both options but either keep returning count = 1 instead of more. When i clear the list the count says its 0 so thats ok.

isSelected() is deprecated so i rather not use that one...any other suggestions?

Former Member
0 Kudos

Hugo,

<i>I do count in the wdDoModifyView. Can anyone tell me why this aint working?</i>

Try to count in some action handler. What count is reported?

VS

Former Member
0 Kudos

Hugo,

create a context attribute "counter" of type integer. Set the "calculated"-property of this attribute to "true" and "readonly"-property to "true". Go to the implementation of your view and add this to the method "getCounter(...)":


int counter = 0;
    
for (int i = 0; i < wdContext.nodeData().size(); i++) {
		
	if(wdContext.nodeData().isMultiSelected(i)) {
		counter++;
	} 
			
}
        
return counter;

Also set the "initializeLeadSelection"-property of your tables context node to "false" or set the counter attribute to "1" in wdDoInit().

Regards

Sebastian

Former Member
0 Kudos

When i try the count in another method, it does show the correct amount!

The problem is i show details when a task is selected and i want to clear the details when multiple are selected so in which event can i do this....i thought wdDoModifyView() would be good because it is triggered every time the view changes but apparently this isnt working. I also tried the count in onActionDetailsClicked() which is the event which is triggered when i select a row in the table but when i select the first row..it's triggered but when i add a second one...it's not.

Any ideas?

Former Member
0 Kudos

Hugo,

You've answered your question: do not use wdDoModifyView.

When multiple selection occured, a postback is sent to server. However, information sent with this postback does not contains updated values or selection changes. The only methods invoked with such postback are calculated attribute accessors and wdDoModifyView, but, as you see wdDoModifyiew is useless in this case.

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

There is no event handler for multi-selection, only for lead-selection. Thus the only way is to use an action triggered by another UI element (e.g. a button).

Armin

Former Member
0 Kudos

aaah, ok. So i guess there is no way to make it possible without an extra action from the user...clicking an extra button or so.

Ill put it on my wishlist

Thanks anyway..

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Valery,

wdDoModifyView() is <u>not </u>invoked by the WD Runtime within multiselection roundtrips, as no action was triggered. The calculated getter/setter methods are invoked, as the related values are not cached by the client.

Regards, Bertram

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

try this

IPrivate<ViewName>.I<Name>Node nodeCheck=wdContext.node<Name>();

int count=0;

int size=nodeCheck.size();

for(int j=0;j<size;j++){

if(nodeCheck.isSelected(j)){

count=count+1;

}

}

Kind Regards

Mukesh

Former Member
0 Kudos

Hi,

Is 'Task' really the node that is bound to your table (check table datasource)?

Is the selectionMode (table properties) set to multi?

Good luck,

Roelof