anasande
29 Dec 2010, 1:34 AM
Hi. I'm experimenting some problems with a paged simple selection grid with checkboxes. If I play cliking on different rows of my grid results, when I change the page the grid shows with all that rows selected, eventhough I defined it as SelectionMode.SIMPLE. I tried to fix it forcing to deselect all rows with grid.getSelectionModel().deselectAll() after grid recharge, but it didn't work.
Here you have my grid code:
private Grid<MyObjectDTO> createGrid() {
cm = columnsConfiguration();
final Map<String, Object> param = new HashMap<String, Object>();
param.put("parameter",myParameter);
RpcProxy<PagingLoadResult<MyObjectDTO>> proxy = new RpcProxy<PagingLoadResult<MyObjectDTO>>() {
@Override
protected void load(Object loadConfig,
AsyncCallback<PagingLoadResult<MyObjectDTO>> callback) {
tiService.findResults((PagingLoadConfig) loadConfig,
param, callback);
}
};
// loader
final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(
proxy);
loader.setRemoteSort(true);
ListStore<MyObjectDTO> store = new ListStore<MyObjectDTO>(loader);
bottomToolBar.bind(loader);
grid = new Grid<MyObjectDTO>(store, cm);
grid.addListener(Events.RowClick,
new Listener<GridEvent<MyObjectDTO>>() {
public void handleEvent(GridEvent<MyObjectDTO> be) {
Integer selected = be.getRowIndex();
MyObjectDTO ej = be.getGrid().getStore().getAt(
selected);
// Some checking code in the selected item
}
}
});
grid.addListener(Events.Attach,
new Listener<GridEvent<MyObjectDTO>>() {
public void handleEvent(GridEvent<MyObjectDTO> be) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(elementsPerPage);
Map<String, Object> state = grid.getState();
if (state.containsKey("offset")) {
int offset = (Integer) state.get("offset");
int limit = (Integer) state.get("limit");
config.setOffset(offset);
config.setLimit(limit);
}
if (state.containsKey("sortField")) {
config
.setSortField((String) state
.get("sortField"));
config.setSortDir(SortDir.valueOf((String) state
.get("sortDir")));
}
loader.load(config);
}
});
grid.setLoadMask(true);
grid.setBorders(true);
selectionModel.bindGrid(grid);
return grid;
}
// Grid column configuration
private ColumnModel columnsConfiguration() {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
selectionModel = new CheckBoxSelectionModel<MyObjectDTO>();
selectionModel.setSelectionMode(SelectionMode.SIMPLE);
configs.add(selectionModel.getColumn());
ColumnConfig column = new ColumnConfig();
column = new ColumnConfig();
column.setId("idMyObject");
column.setHeader("id");
column.setWidth(70);
configs.add(column);
column = new ColumnConfig();
column.setId("description");
column.setHeader("description");
column.setWidth(300);
configs.add(column);
return new ColumnModel(configs);
}
Can anyone help me? Thank you very much in advance.
Here you have my grid code:
private Grid<MyObjectDTO> createGrid() {
cm = columnsConfiguration();
final Map<String, Object> param = new HashMap<String, Object>();
param.put("parameter",myParameter);
RpcProxy<PagingLoadResult<MyObjectDTO>> proxy = new RpcProxy<PagingLoadResult<MyObjectDTO>>() {
@Override
protected void load(Object loadConfig,
AsyncCallback<PagingLoadResult<MyObjectDTO>> callback) {
tiService.findResults((PagingLoadConfig) loadConfig,
param, callback);
}
};
// loader
final PagingLoader<PagingLoadResult<ModelData>> loader = new BasePagingLoader<PagingLoadResult<ModelData>>(
proxy);
loader.setRemoteSort(true);
ListStore<MyObjectDTO> store = new ListStore<MyObjectDTO>(loader);
bottomToolBar.bind(loader);
grid = new Grid<MyObjectDTO>(store, cm);
grid.addListener(Events.RowClick,
new Listener<GridEvent<MyObjectDTO>>() {
public void handleEvent(GridEvent<MyObjectDTO> be) {
Integer selected = be.getRowIndex();
MyObjectDTO ej = be.getGrid().getStore().getAt(
selected);
// Some checking code in the selected item
}
}
});
grid.addListener(Events.Attach,
new Listener<GridEvent<MyObjectDTO>>() {
public void handleEvent(GridEvent<MyObjectDTO> be) {
PagingLoadConfig config = new BasePagingLoadConfig();
config.setOffset(0);
config.setLimit(elementsPerPage);
Map<String, Object> state = grid.getState();
if (state.containsKey("offset")) {
int offset = (Integer) state.get("offset");
int limit = (Integer) state.get("limit");
config.setOffset(offset);
config.setLimit(limit);
}
if (state.containsKey("sortField")) {
config
.setSortField((String) state
.get("sortField"));
config.setSortDir(SortDir.valueOf((String) state
.get("sortDir")));
}
loader.load(config);
}
});
grid.setLoadMask(true);
grid.setBorders(true);
selectionModel.bindGrid(grid);
return grid;
}
// Grid column configuration
private ColumnModel columnsConfiguration() {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
selectionModel = new CheckBoxSelectionModel<MyObjectDTO>();
selectionModel.setSelectionMode(SelectionMode.SIMPLE);
configs.add(selectionModel.getColumn());
ColumnConfig column = new ColumnConfig();
column = new ColumnConfig();
column.setId("idMyObject");
column.setHeader("id");
column.setWidth(70);
configs.add(column);
column = new ColumnConfig();
column.setId("description");
column.setHeader("description");
column.setWidth(300);
configs.add(column);
return new ColumnModel(configs);
}
Can anyone help me? Thank you very much in advance.