PDA

View Full Version : How to get selected row from a grid ?



Yacho
9 Dec 2009, 7:22 PM
Hi !

I init my grid in such a way :


[....]
PagingLoader<PagingLoadResult<ModelData>> loaderZabytki = new BasePagingLoader<PagingLoadResult<ModelData>>(
proxyZabytki);
loaderZabytki.setRemoteSort(false);
this.zabytkiStore = new ListStore<Zabytek>(loaderZabytki);
Grid<Zabytek> gridZabytki = new Grid<Zabytek>(this.zabytkiStore, zt
.getCm());
gridZabytki.addPlugin(new RowNumberer());
gridZabytki.setStyleAttribute("borderTop", "none");
gridZabytki.setAutoExpandColumn("KATASTER_NR");
gridZabytki.setBorders(true);
gridZabytki.setStripeRows(true);
gridZabytki.setStateId("pagingGridExample");
gridZabytki.setStateful(true);
gridZabytki.addListener(Events.Attach, new AttachZabytki(gridZabytki,
loaderZabytki));
gridZabytki.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
gridZabytki.getSelectionModel().addSelectionChangedListener(
new SelectionChangedListener<Zabytek>() {

@Override
public void selectionChanged(
SelectionChangedEvent<Zabytek> se) {
GWT.log("Zmieniono selekcje !", null);
getDisplay().getEditZabytekButton().setEnabled(true);
getDisplay().getDelZabytekButton().setEnabled(true);

}
});
gridZabytki.setLoadMask(true);

zt.getToolbar().bind(loaderZabytki);

zt.add(gridZabytki);

And when i run :

Zabytek toEdit = zt.getGrid().getSelectionModel().getSelectedItem();
i always get null - am I missing something ?

VadimV1144
10 Dec 2009, 12:00 AM
You can save the reference to the selected item.


selectionChanged(SelectionChangedEvent<Zabytek> se){
....
toEdit = se.getSelectedItem();
}

Where toEdit is class member.

Arno.Nyhm
10 Dec 2009, 7:47 AM
the idea is like VadimV1144 say you can use the SelectionChangeEvent directly



myGrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<BaseModelData>() {

@Override
public void selectionChanged(SelectionChangedEvent<BaseModelData> se) {
GWT.log("selection change selected " + se.getSelection().size() + " item " + (se.getSelectedItem() == null ? "none" : se.getSelectedItem().toString()), null);
}
}