PDA

View Full Version : How to set CheckboxSelectionModel initial values



pkarnati
26 Nov 2009, 10:14 AM
have problem in pre-selecting checkbox in grid using
CheckBoxSelectionModel cbsm;
cbsm = new CheckBoxSelectionModel();
cbsm.getColumn().setDataIndex("active");
cbsm.getColumn().setSortable(false);
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
configs.add(cbsm.getColumn());
configs.get(0).setSortable(false);
ColumnConfig column = new ColumnConfig();
column.setId("name");
column.setHeader("Company");
column.setWidth(200);
configs.add(column);
column = new ColumnConfig();
column.setId("symbol");
column.setHeader("Symbol");
column.setWidth(100);
configs.add(column);

searching for 'active' col true ,false and select the checkbox for true rows.

Grid<Stock> grid = new Grid<Stock>(store, cm);
List checkedStore = grid.getStore().getModels();
List<Stock> temp =null;
ListStore<Stock> newStore = new ListStore<Stock>();
GridSelectionModel<Stock> a1= grid.getSelectionModel();
for(int i= 0 ;i<checkedStore.size();i++){
Stock a = (Stock)checkedStore.get(i);
if (a.getActive()) {
newStore.add(a);
}
}
a1.setSelection(newStore.getModels());
grid.setSelectionModel(a1);
not knowing how to pre-select checkbox.

thanks in advance

wekion
1 Dec 2009, 2:17 AM
this seems to be fixed in 2.1.0. i had the same problem in 2.0.1 but upgrading seems to have nailed it. ~o)

pkarnati
1 Dec 2009, 6:44 AM
am using ext gwt 2.1.0 . could you please give the code snippet that is working for pre-selecting checkboxes in grid using checkboxselectionmodel