Hi,
I have a scenario like i have to pick records from a picklist and add to listgrid. That listgrid contains grouping feature. When the grouping is enabled, listgrid.setData(records) is not working. that means selected records are not getting added to listgrid. If I disable the grouping listgrid.setData(records) works.
//list grid which contains grouping feature
Listgrid shipmentGrid = new ListGrid();
shipmentGrid.setCanFocus(false);
shipmentGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
shipmentGrid.setSelectionType(SelectionStyle.SIMPLE);
shipmentGrid.setAlternateRecordStyles(true);
shipmentGrid.setAutoFetchData(false);
shipmentGrid.setDataSource(ShipmentConditionMasterDS.getInstance());
shipmentGrid.setWidth(900);
shipmentGrid.setHeight(300);
shipmentGrid.setHeaderHeight(40);
shipmentGrid.setCanSort(true);
shipmentGrid.setShowRecordComponents(true);
shipmentGrid.setShowAllRecords(true);
shipmentGrid.setShowRecordComponentsByCell(true);
shipmentGrid.setGroupStartOpen(GroupStartOpen.ALL);
shipmentGrid.setGroupByField(FieldName.GROUP_NAME);
shipmentGrid.setCanEdit(true);
shipmentGrid.setAutoSaveEdits(true);
ListGridField remove = ClientComponentUtil.getDefaultListGridField(FieldName.REMOVE, " ", 30);
remove.setType(ListGridFieldType.IMAGE);
remove.setShowRollOverIcon(true);
remove.setShowFocusedIcon(true);
ListGridField listIndex = ClientComponentUtil.getDefaultHiddenListGridField( RENConstants.FieldName.LIST_INDEX, RENConstants.FieldTitle.LIST_INDEX, 30);
ListGridField include = ClientComponentUtil.getDefaultListGridField(FieldName.INCLUDE, FieldTitle.INCLUDE, 80); include.setType(ListGridFieldType.BOOLEAN);
ListGridField value = ClientComponentUtil.getDefaultListGridField(FieldName.VALUE, FieldTitle.VALUE, 150);
ListGridField rangeFrom = ClientComponentUtil.getDefaultListGridField(FieldName.RANGE_FROM, FieldTitle.RANGE_FROM, 150);
ListGridField rangeTo = ClientComponentUtil.getDefaultListGridField(FieldName.RANGE_TO, FieldTitle.RANGE_TO, 150);
ListGridField type = ClientComponentUtil.getDefaultListGridField(FieldName.TYPE, FieldTitle.TYPE, 100); type.setCanEdit(false);
ListGridField title = ClientComponentUtil.getDefaultListGridField(FieldName.TITLE, FieldTitle.TITLE);
title.setWidth(Constant.Percentage.PERCENTAGE_100);
title.setCanEdit(false);
ListGridField groupName = new ListGridField(FieldName.GROUP_NAME);
groupName.setHidden(true);
groupName.setGroupValueFunction(new com.smartgwt.client.widgets.grid.GroupValueFunction() {
@Override
public Object getGroupValue(Object o, ListGridRecord listGridRecord, ListGridField listGridField, String s, ListGrid listGrid) {
String val = (String) o;
if (val.equals("")) {
return FieldTitle.INDEPENDENT;
} else {
return o.toString();
}
}
});
groupName.setGroupTitleRenderer(new GroupTitleRenderer() {
@Override
public String getGroupTitle(Object o, GroupNode groupNode, ListGridField listGridField, String s, ListGrid listGrid) {
String val = o.toString();
if (val.equals(FieldTitle.INDEPENDENT)) {
return "P " + FieldTitle.INDEPENDENT;
} else {
return "P " + commonForm.getValueAsString(FieldName.ACTIONS) + " " + 1;
}
}
});
shipmentGrid.setFields(include, listIndex, title, value, rangeFrom, rangeTo, groupName, type, remove);
//Pick list grid to select records
pickListGrid.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
event.getRecord().setAttribute(RENConstants.FieldName.STATUS, RENConstants.Constants.ADDED);
addToShipmentGrid(event.getRecord());
pickListGrid.redraw();
}
});
//Set selected record to listgrid
private void addToShipmentGrid(ListGridRecord record) {
RecordList recordList = shipmentGrid.getRecordList();
List<String> list = new ArrayList<>();
List<ListGridRecord> records = Arrays.asList(shipmentGrid.getRecords());
record.setAttribute(RENConstants.FieldName.INCLUDE, true);
if (CommonToolkit.isNotNull(records)) {
list = ClientUtil.getRecordValues(records, RENConstants.FieldName.SHIPMENT_CONDITION_CODE);
if (!list.contains(record.getAttribute(RENConstants.FieldName.SHIPMENT_CONDITION_CODE))) {
recordList.add(record);
}
} else {
recordList.add(record);
}
shipmentGrid.setData(recordList);
}
I have a scenario like i have to pick records from a picklist and add to listgrid. That listgrid contains grouping feature. When the grouping is enabled, listgrid.setData(records) is not working. that means selected records are not getting added to listgrid. If I disable the grouping listgrid.setData(records) works.
//list grid which contains grouping feature
Listgrid shipmentGrid = new ListGrid();
shipmentGrid.setCanFocus(false);
shipmentGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
shipmentGrid.setSelectionType(SelectionStyle.SIMPLE);
shipmentGrid.setAlternateRecordStyles(true);
shipmentGrid.setAutoFetchData(false);
shipmentGrid.setDataSource(ShipmentConditionMasterDS.getInstance());
shipmentGrid.setWidth(900);
shipmentGrid.setHeight(300);
shipmentGrid.setHeaderHeight(40);
shipmentGrid.setCanSort(true);
shipmentGrid.setShowRecordComponents(true);
shipmentGrid.setShowAllRecords(true);
shipmentGrid.setShowRecordComponentsByCell(true);
shipmentGrid.setGroupStartOpen(GroupStartOpen.ALL);
shipmentGrid.setGroupByField(FieldName.GROUP_NAME);
shipmentGrid.setCanEdit(true);
shipmentGrid.setAutoSaveEdits(true);
ListGridField remove = ClientComponentUtil.getDefaultListGridField(FieldName.REMOVE, " ", 30);
remove.setType(ListGridFieldType.IMAGE);
remove.setShowRollOverIcon(true);
remove.setShowFocusedIcon(true);
ListGridField listIndex = ClientComponentUtil.getDefaultHiddenListGridField( RENConstants.FieldName.LIST_INDEX, RENConstants.FieldTitle.LIST_INDEX, 30);
ListGridField include = ClientComponentUtil.getDefaultListGridField(FieldName.INCLUDE, FieldTitle.INCLUDE, 80); include.setType(ListGridFieldType.BOOLEAN);
ListGridField value = ClientComponentUtil.getDefaultListGridField(FieldName.VALUE, FieldTitle.VALUE, 150);
ListGridField rangeFrom = ClientComponentUtil.getDefaultListGridField(FieldName.RANGE_FROM, FieldTitle.RANGE_FROM, 150);
ListGridField rangeTo = ClientComponentUtil.getDefaultListGridField(FieldName.RANGE_TO, FieldTitle.RANGE_TO, 150);
ListGridField type = ClientComponentUtil.getDefaultListGridField(FieldName.TYPE, FieldTitle.TYPE, 100); type.setCanEdit(false);
ListGridField title = ClientComponentUtil.getDefaultListGridField(FieldName.TITLE, FieldTitle.TITLE);
title.setWidth(Constant.Percentage.PERCENTAGE_100);
title.setCanEdit(false);
ListGridField groupName = new ListGridField(FieldName.GROUP_NAME);
groupName.setHidden(true);
groupName.setGroupValueFunction(new com.smartgwt.client.widgets.grid.GroupValueFunction() {
@Override
public Object getGroupValue(Object o, ListGridRecord listGridRecord, ListGridField listGridField, String s, ListGrid listGrid) {
String val = (String) o;
if (val.equals("")) {
return FieldTitle.INDEPENDENT;
} else {
return o.toString();
}
}
});
groupName.setGroupTitleRenderer(new GroupTitleRenderer() {
@Override
public String getGroupTitle(Object o, GroupNode groupNode, ListGridField listGridField, String s, ListGrid listGrid) {
String val = o.toString();
if (val.equals(FieldTitle.INDEPENDENT)) {
return "P " + FieldTitle.INDEPENDENT;
} else {
return "P " + commonForm.getValueAsString(FieldName.ACTIONS) + " " + 1;
}
}
});
shipmentGrid.setFields(include, listIndex, title, value, rangeFrom, rangeTo, groupName, type, remove);
//Pick list grid to select records
pickListGrid.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
event.getRecord().setAttribute(RENConstants.FieldName.STATUS, RENConstants.Constants.ADDED);
addToShipmentGrid(event.getRecord());
pickListGrid.redraw();
}
});
//Set selected record to listgrid
private void addToShipmentGrid(ListGridRecord record) {
RecordList recordList = shipmentGrid.getRecordList();
List<String> list = new ArrayList<>();
List<ListGridRecord> records = Arrays.asList(shipmentGrid.getRecords());
record.setAttribute(RENConstants.FieldName.INCLUDE, true);
if (CommonToolkit.isNotNull(records)) {
list = ClientUtil.getRecordValues(records, RENConstants.FieldName.SHIPMENT_CONDITION_CODE);
if (!list.contains(record.getAttribute(RENConstants.FieldName.SHIPMENT_CONDITION_CODE))) {
recordList.add(record);
}
} else {
recordList.add(record);
}
shipmentGrid.setData(recordList);
}
Comment