PDA

View Full Version : CheckboxSelectionModel-GXT



sbarakat
16 Nov 2009, 10:11 PM
Hello,

I have a grid that contain a CheckboxSelectionModel. I am filling the column information on grid RENDER(Events.Render) using the CheckboxSelectionModel.select(List) and in the same method i am refreshing the grid using grid.getView.Refresh(true);
the problem is: When loading the grid I got the selected checkboxes, then and at the same time the selected information will be unselected again. It seems that there is a certain action unselect them again.

Does anyone faced this problem or can anyone help to solve this problem.

Thanks

sven
17 Nov 2009, 4:49 AM
You should post your code in a runnable examlpe. Please also note that the render event is the wrong event for the thing you are trying to do.

sbarakat
17 Nov 2009, 11:48 PM
Below you will find the method that display the grid with the selection model:

private void displayGrid(final String gsId) {

selWindow = new Window();
selWindow.setHeading(Constant.WORKFLOWLIST_TITLE);
selWindow.setClosable(true);
selWindow.setWidth(350);
selWindow.setHeight(250);
selWindow.setPlain(true);
selWindow.setResizable(true);
selWindow.setModal(true);
selWindow.setLayout(new FitLayout());
selWindow.setClosable(true);
selWindow.setButtonAlign(HorizontalAlignment.CENTER);

cbSelectionModel = new CheckBoxSelectionModel<ModelData>();
ArrayList<ColumnConfig> configs = new ArrayList<ColumnConfig>();

cbSelectionModel.setSelectionMode(SelectionMode.MULTI);
configs.add(cbSelectionModel.getColumn());


ColumnConfig idCol = new ColumnConfig();
idCol.setFixed(true);
idCol.setSortable(true);
idCol.setId("wfId");
idCol.setHeader("Id");
idCol.setWidth(50);
idCol.setAlignment(HorizontalAlignment.RIGHT);
idCol.setStyle("white-space:normal;height: 18px;");
configs.add(idCol);

ColumnConfig nameCol = new ColumnConfig();
nameCol.setFixed(true);
nameCol.setSortable(true);
nameCol.setId("wfName");
nameCol.setHeader("Workflow");
nameCol.setStyle("white-space:normal;height: 18px;");
configs.add(nameCol);

columnModel = new ColumnModel(configs);

grid = new Grid<ModelData>(gridStore, columnModel);

grid.setStripeRows(true);
grid.setAutoExpandColumn("wfName");

grid.setWidth(200);
grid.setHeight(350);

grid.setStyleName("grid-icon");
grid.setSelectionModel(cbSelectionModel);
grid.addPlugin(cbSelectionModel);

grid.addListener(Events.Render, new Listener<GridEvent<ModelData>>() {
public void handleEvent(GridEvent<ModelData> ge) {
int length = gridStore.getCount();
List<ModelData> selRecordsLst = new ArrayList<ModelData>(length);
int cnt = 0;

for (int i = 0; i < length; i++) {
ModelData selRecords = gridStore.getAt(i);
String wfId = selRecords.get("wfId");
String gsValue = gsResult.get(wfId).get(gsId);
if (Constant.isDefined(gsValue) && "1".equals(gsValue)) {
selRecordsLst.add(selRecords);
cnt++;
}
}
cbSelectionModel.select(selRecordsLst, true);
grid.getView().refresh(true);
}
});

Button okButton = new Button("OK");
okButton.addListener(Events.OnClick, new Listener<ButtonEvent>() {
public void handleEvent(ButtonEvent be) {
HashMap<String, String> rec = new HashMap<String, String>();
List<ModelData> selecteditemsLst = cbSelectionModel.getSelectedItems();
String wfId = "";
String wfName = "";
for (int i = 0; i < selecteditemsLst.size(); i++) {
wfId = selecteditemsLst.get(i).get("wfId");
wfName = selecteditemsLst.get(i).get("wfName");
rec.put(wfId, "1");
}
Iterator<String> it = gsResult.keySet().iterator();
while (it.hasNext()) {
wfId = (String) it.next();
gsResult.get(wfId).put(gsId, (rec.get(wfId) != null) ? "1" : "0");
}
TextField lkpTxt = (TextField) ComponentManager.get().get(gsId + "_Txt");
lkpTxt.setValue((selecteditemsLst.size() == 1) ? wfName : "(" + selecteditemsLst.size() + ") Selections");
selWindow.hide();
}
});
selWindow.add(grid);

selWindow.addButton(okButton);

Button cancelButton = new Button("Cancel");
cancelButton.addListener(Events.OnClick, new Listener<ButtonEvent>() {
public void handleEvent(ButtonEvent be) {
selWindow.hide(null);
}
});
selWindow.addButton(cancelButton);
selWindow.show();
}

sbarakat
20 Nov 2009, 11:24 PM
I sent u a piece of code.
Any feedback on this?