Hi all,
I have a list grid which has a number of rows containing checkboxes.
What I'm trying to achieve is when a check box is ticked, all the check boxes in the row is ticked. SO I almost have is working...
Data Source
The issue I have is when the selection check box is used, and I select all the checkbox fields in the selection change hander, when I call save, the changed data is not passed.
So I assume the problem is in my selection changed handler, updating the record I'm guessing is not marking the cells as updated.
HOw can I achieve this? I've tried refreshing the row, and calling applyRowData(), they didn't seem to work either.
Thanks,
Dale
I have a list grid which has a number of rows containing checkboxes.
What I'm trying to achieve is when a check box is ticked, all the check boxes in the row is ticked. SO I almost have is working...
Code:
private void setupRoleList() {
listGrid.setWidth100();
listGrid.setHeight100();
listGrid.setDataSource(CaseTypeRoleDS.getInstance(caseType.getCode()));
listGrid.setSortField(CaseTypeRoleDS.NAME);
listGrid.setShowHeaderContextMenu(false);
listGrid.setCanDragResize(false);
listGrid.setCanSort(false);
listGrid.setAutoSaveEdits(false);
listGrid.setSelectionType(SelectionStyle.SIMPLE);
listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
layout.addMember(listGrid);
// Set the action checkboxes to 55 width
listGrid.addDrawHandler(new DrawHandler() {
@Override
public void onDraw(DrawEvent drawEvent) {
listGrid.setAutoFitData(Autofit.HORIZONTAL);
for (ListGridField field : listGrid.getFields()) {
if (!field.getName().equals(CaseTypeRoleDS.NAME)) {
field.setWidth(55);
field.setCanEdit(true);
}
}
}
});
listGrid.addDataArrivedHandler(new DataArrivedHandler() {
@Override
public void onDataArrived(DataArrivedEvent dataArrivedEvent) {
for (ListGridRecord record : listGrid.getRecords()) {
if (record.getAttributeAsBoolean(CaseTypeRoleDS.ALL_ALLOWED)) {
listGrid.selectRecord(record);
}
}
}
});
listGrid.addSelectionChangedHandler(new SelectionChangedHandler() {
@Override
public void onSelectionChanged(SelectionEvent selectionEvent) {
if (selectionEvent.getSelection() != null) {
ListGridRecord record = selectionEvent.getRecord();
boolean selected = listGrid.isSelected(record);
for (String attributeName : record.getAttributes()) {
if (!attributeName.equals(CaseTypeRoleDS.NAME) && !attributeName.equals(CaseTypeRoleDS.ID)) {
record.setAttribute(attributeName, selected);
}
}
//RecordList recordList = new RecordList(new Record[] { record });
//listGrid.applyRowData(recordList);
//int rowIndex = listGrid.getRecordList().indexOf(record);
//listGrid.refreshRow(rowIndex);
listGrid.redraw();
}
}
});
}
Code:
@Override
protected void executeUpdate(final String requestId, DSRequest request, final DSResponse response) {
final ListGridRecord record = new ListGridRecord(request.getData());
Integer roleId = null;
Map<String, Boolean> updates = new HashMap<String, Boolean>();
for (String attributeName : record.getAttributes()) {
if (attributeName.equals(ID)) {
roleId = record.getAttributeAsInt(attributeName);
} else if (!attributeName.startsWith("_check")) {
updates.put(attributeName, record.getAttributeAsBoolean(attributeName));
}
}
RpcServiceLocator.getRoleService().updateCaseTypePermissions(roleId, caseTypeCode, updates, new ErrorMessageCallback<RoleDto>("Failed to update role") {
@Override
public void onSuccess(RoleDto roleDto) {
response.setData(new Record[]{mapper.map(roleDto)});
processResponse(requestId, response);
}
});
}
So I assume the problem is in my selection changed handler, updating the record I'm guessing is not marking the cells as updated.
HOw can I achieve this? I've tried refreshing the row, and calling applyRowData(), they didn't seem to work either.
Thanks,
Dale