PDA

View Full Version : CheckBoxSelectionMode selectAll() problems



Love Yao
10 Jan 2010, 7:39 PM
demo code:
//===================================================================
ListStore<BaseModel> store = new ListStore<BaseModel>();
for (String string : songName) {
BaseModel baseModel = new BaseModel();
baseModel.set("songName", string);
store.add(baseModel);
}

List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
CheckBoxSelectionModel<BaseModel> sm = new CheckBoxSelectionModel<BaseModel>();
configs.add(sm.getColumn());
ColumnConfig column = new ColumnConfig();
column.setId("songName");
column.setHeader("Name");
column.setWidth(200);
configs.add(column);

ColumnModel cm = new ColumnModel(configs);
Grid<BaseModel> grid = new Grid<BaseModel>(store, cm);
grid.setSelectionModel(sm);
grid.addPlugin(sm);
sm.selectAll();//Is this right?
songPanel.add(grid);
songPanel.layout();

songPanel.addButton(new Button("Ok"));
System.out.println(sm.getSelectedItems().size());
//===================================================================

the console get the sm.getSelectedItems().size()=10 not 0,but in fact All the checkbox is not selected? so Do i coding something wrong?

Love Yao
13 Jan 2010, 12:31 AM
help help :((:((:((:((:((:((:((:((:((:((:((:((

Arno.Nyhm
15 Jan 2010, 8:12 AM
maybe you need to test the value after all is rendered. maybe it is resettet between your requesting the value and the finished rendering.



DeferredCommand.addCommand(new Command() {

@Override
public void execute() {
sm.selectAll();
GWT.log(sm.getSelectedItems().size(),null);
}
});

Love Yao
17 Jan 2010, 10:18 PM
I use a button to selectAll() it works!

toggleButton.addSelectionListener(new SelectionListener<ButtonEvent>() {

@Override
public void componentSelected(ButtonEvent ce) {
if (toggleButton.isPressed() == true) {
sm.selectAll();
} else {
sm.deselectAll();
}

}
});


but I try many ways and do not know how to selectAll the items when the first time the grid onRender:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((:((

Arno.Nyhm
18 Jan 2010, 6:44 AM
please answer also if someone helps you: did you try my example?


if you use your butten then the store is filled. and it works. so you have to select the items after the store is loaded:



store.getLoader().addListener(Loader.Load, new Listener<LoadEvent>()
{
public void handleEvent(LoadEvent le)
{
tableGrid.getSelectionModel().selectAll();;
}
});

see here:
http://www.extjs.com/forum/showthread.php?p=427864#post427864

Love Yao
18 Jan 2010, 6:10 PM
I try your codes ,but do not have any result.

I do not use loader.
All the code is in :
My rpc onSuccess()

public void onSuccess(List<String> result) {

for (String string : songName) {
BaseModel baseModel = new BaseModel();
baseModel.set("songName", string);
store.add(baseModel);
}


my demo code................

}


so in my demo ,the store is filled.
I think it is a problem of where to code "sm.selectAll()"