-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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(); ..... }
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
Asked: 2010-10-01 05:44:41 +0800
Seen: 1,314 times
Last updated: Aug 10 '11