PDA

View Full Version : [gxt 1.1.x] getSelectionModel().getSelectedItem() doesn't work on Editable Grids



AlexPdro
29 Aug 2008, 12:36 AM
Config :

gxt-1.1-alpha1 -> 3
Windows XP
Host modeProblem :
I looks like it is not possible to retrieve the selected model of an EditorGrid. It makes it impossible to delete a row from an editable grid.

Code :


public class Test implements EntryPoint {
public void onModuleLoad() {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig("c1", "Column 1", 150);
column.setEditor(new CellEditor(new TextField<String>()));
configs.add(column);
column = new ColumnConfig("c2", "Column 2", 150);
column.setEditor(new CellEditor(new TextField<String>()));
configs.add(column);
ColumnModel cm = new ColumnModel(configs);

ListStore<MyModel> store = new ListStore<MyModel>();
for (int i = 0; i < 20; i++) {
store.add(new MyModel("c1-" + (i+1), "c2-" + (i+1)));
}

final EditorGrid<MyModel> grid = new EditorGrid<MyModel>(store, cm);
grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
grid.setBorders(true);
grid.setSize(324, 300);
RootPanel.get().add(grid);

Button removeItem = new Button("Remove", new SelectionListener<ComponentEvent>() {
public void componentSelected(ComponentEvent ce) {
MyModel l_selectedValue = grid.getSelectionModel().getSelectedItem();
if(l_selectedValue != null) {
grid.getStore().remove(l_selectedValue);
}
}
});
RootPanel.get().add(removeItem);
}
public static class MyModel extends BaseModel
{
public MyModel(String value1, String value2)
{
set("c1", value1);
set("c2", value2);
}
}
}

The code is adapted from the topic :
[FIXED] Removing an element from a grid store throws exception

gslender
30 Aug 2008, 5:18 AM
I'm using editor grid and it works fine for me, though I'm getting the selected item differently to you so perhaps that's the issue for you.



final CellSelectionModel<BeanModel> csm = new CellSelectionModel<BeanModel>();
grid.setSelectionModel(csm);
grid.addListener(Events.CellClick, new Listener<GridEvent>() {
public void handleEvent(GridEvent ge) {
editToolItem.setEnabled(true);
delToolItem.setEnabled(true);
currentlySelectedItem = csm.getSelectCell().model;
}
});