PDA

View Full Version : How to enable SelectionMode.SIMPLE on CheckBoxSelectionModel in Grid?



bitkopf
9 Feb 2012, 12:42 PM
Hi,
i try to make multiple rows selectable through checkboxes in a grid without pressing Ctrl or Shift.
I have extracted my problem by this test case:


public class Test implements EntryPoint{

class Dummy extends BaseModel{
public Dummy() {
set("name", "Dummy" );
}
}

@Override
public void onModuleLoad() {

ListStore<Dummy> store = new ListStore<Dummy>();
store.add(new Dummy());
store.add(new Dummy());

List<ColumnConfig> columns = new ArrayList<ColumnConfig>();

CheckBoxSelectionModel<Dummy> sm = new CheckBoxSelectionModel<Dummy>();
sm.setSelectionMode(SelectionMode.SIMPLE);
columns.add(sm.getColumn());

ColumnConfig cc = new ColumnConfig("name", 100);
columns.add(cc);

ColumnModel cm = new ColumnModel(columns);

Grid<Dummy> grid = new Grid<Dummy>(store, cm);

RootPanel.get().add(grid);

}
}
"sm.setSelectionMode(SelectionMode.SIMPLE);" seems to be completely ignored. Why?

storm8
14 Feb 2012, 12:35 AM
i have the same problem and after few shot i solve problem using the following statement

grid.setSelectionModel(sm);

the object "sm" i create like follwing

CheckBoxSelectionModel<YourModelData> sm = new CheckBoxSelectionModel<YourModelData>();
sm.setSelectionMode(SelectionMode.MULTI);
configs.add(sm.getColumn());

smiletolead
14 Feb 2012, 12:59 AM
You need to add selection model to the grid as a selection model and a plugin. Add these two lines of code:



grid.setSelectionModel(sm);
grid.addPlugin(sm);

bitkopf
14 Feb 2012, 1:11 AM
Great. Thanks a lot!

That seems very redundant.
1. Pass the ColumnModel containing the SelectionModel to the grid in the constructor.
2. Set the SelectionModel for the Grid.
3. Add the SelectionModel as a plugin.

Anyway i'm glad it works :-)