0

How to get grid row index

asked 2010-10-01 05:44:41 +0800

cyiannoulis gravatar image cyiannoulis
1191 10

I have a data bound Grid. Changing the value of a cell fires the onItemCodeChanged(). I can store the index of each row as row's data. Is there a way to retrieve directly the index of the row?

	public void onItemCodeModified(InputEvent event) {
		
		Row row = (Row)event.getTarget().getParent();
		
		Integer index = (Integer)row.getValue();
                .....
	}

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-10-10 04:16:36 +0800

iantsai gravatar image iantsai
2755 1

grid.getRows().getChildren().indexOf(row);

link publish delete flag offensive edit

answered 2011-08-10 02:06:45 +0800

user1 gravatar image user1
48 1

can u explain in detail how to get th eselected index of a particular row in a grid.

link publish delete flag offensive edit

answered 2011-08-10 04:53:48 +0800

cyiannoulis gravatar image cyiannoulis
1191 10

Here is a simple snippet to get an idea.

ZUL code

<grid id="gridContacts" fixedLayout="true" vflex="true"  model="@{ yourmodel }" >
		
	<columns sizable="true">
		<column label="Code" width="100px" />
		<column label="First Name" width="200px" />
		<column label="Last Name" width="250px" />
		<column width="100px" />
	</columns>
	
	<rows>
		<row self="@{each='contact'}" value="@{ selectedContact }">
			<label value="@{ record.code }" />
		        <toolbarbutton label="@{ contact.firstname }" forward="onClick=onEditContact" />
		        <toolbarbutton label="@{ contact.lastname }" forward="onClick=onEditContact" />
			<button label="Delete Line" forward="onClick=onDeleteContact" />
		</row>
	</rows>
</grid>

The composer code

public void onEditContact(Event event) {
	
	Contact contact = getSelectedContact(event);
	....
	edit the selected contact
	....
}

public void onDeleteContact(Event event) {
	
	Contact contact = getSelectedContact(event);
	....
	delete the selected contact
	....
}

private Contact getSelectedContact(Event event) {
	
	if (event instanceof ForwardEvent) {
		ForwardEvent fwevent = (ForwardEvent)event;
		Event eventOrigin = fwevent.getOrigin();
		Row row = (Row) eventOrigin.getTarget().getParent();
		
		Contact selectedContact = (Contact) row.getValue();
		
		return selectedContact;
	}
	
	return null;
}

Hope that helps

/Costas

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-10-01 05:44:41 +0800

Seen: 1,313 times

Last updated: Aug 10 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More