SmartClient Version: v11.0p_2017-02-11/PowerEdition Deployment (built 2017-02-11)
I want to change options in another selectItem when value of one selectItem changed while editing a row in Grid. I have referred dependent select from smart client showcase for this.(http://www.smartclient.com/smartgwt/...bobox_category )
If There are only select items in a dynamic form then that example from showcase work properly but in case of editing a row in grid this is not working i.e. changing value in one select item does not change the options in another select item.
Sample code:
public void onModuleLoad() {
ListGrid grid = new ListGrid();
ListGridField first = new ListGridField("first");
ListGridField second = new ListGridField("second");
ListGridRecord record = new ListGridRecord();
record.setAttribute("first", "3");
record.setAttribute("second", "test");
List<ListGridRecord> records = new ArrayList<>();
records.add(record);
grid.setFields(first, second);
ListGridRecord[] recordArray = records.toArray(new ListGridRecord[records.size()]);
grid.setRecords(recordArray);
final SelectItem categoryItem = new SelectItem();
categoryItem.setName("materialId");
categoryItem.setPickListWidth(210);
categoryItem.setDisplayField("materialId");
categoryItem.setValueField("materialId");
categoryItem.setTitle("Material");
categoryItem.setOptionDataSource(getMaterialDataSource());
SelectItem itemName = new SelectItem() {
@Override
protected Criteria getPickListFilterCriteria() {
Integer materialId = (Integer) categoryItem.getValue();
Criteria criteria = new Criteria();
criteria.addCriteria("materialId", materialId);
return criteria;
}
};
itemName.setName("description");
itemName.setTitle("Item");
itemName.setDisplayField("description");
categoryItem.setValueField("description");
itemName.setPickListWidth(250);
itemName.setOptionDataSource(getMatAttrDataSource());
grid.setCanEdit(true);
first.setEditorProperties(categoryItem);
second.setEditorProperties(itemName);
grid.draw();
}
private static RestDataSource getMaterialDataSource() {
RestDataSource materialDS = new RestDataSource();
materialDS.setDataFormat(DSDataFormat.JSON);
materialDS.setID("materialDs");
materialDS.setDataURL("/vendor/getMaterials");
DataSourceField materialId = new DataSourceField("materialId", FieldType.INTEGER, "materialId");
materialId.setPrimaryKey(true);
DataSourceField materialField = new DataSourceField("materialCode", FieldType.TEXT, "materialCode");
DataSourceField descriptionField = new DataSourceField("description", FieldType.TEXT, "description");
materialDS.setFields(materialId, materialField, descriptionField);
materialDS.setJsonPrefix("");
materialDS.setJsonSuffix("");
return materialDS;
}
private static RestDataSource getMatAttrDataSource() {
RestDataSource materialAttrTypeDS = new RestDataSource();
materialAttrTypeDS.setID("materialAttrTypeDS");
materialAttrTypeDS.setDataFormat(DSDataFormat.JSON);
materialAttrTypeDS.setDataURL("/vendor/getMaterialAttrType");
DataSourceField materialId = new DataSourceField("materialId", FieldType.INTEGER, "materialId");
materialId.setForeignKey("materialDs.materialId");
materialId.setPrimaryKey(true);
DataSourceField descriptionField = new DataSourceField("description", FieldType.TEXT, "description");
materialAttrTypeDS.setFields(materialId, descriptionField);
materialAttrTypeDS.setJsonPrefix("");
materialAttrTypeDS.setJsonSuffix("");
return materialAttrTypeDS;
}
I want to change options in another selectItem when value of one selectItem changed while editing a row in Grid. I have referred dependent select from smart client showcase for this.(http://www.smartclient.com/smartgwt/...bobox_category )
If There are only select items in a dynamic form then that example from showcase work properly but in case of editing a row in grid this is not working i.e. changing value in one select item does not change the options in another select item.
Sample code:
public void onModuleLoad() {
ListGrid grid = new ListGrid();
ListGridField first = new ListGridField("first");
ListGridField second = new ListGridField("second");
ListGridRecord record = new ListGridRecord();
record.setAttribute("first", "3");
record.setAttribute("second", "test");
List<ListGridRecord> records = new ArrayList<>();
records.add(record);
grid.setFields(first, second);
ListGridRecord[] recordArray = records.toArray(new ListGridRecord[records.size()]);
grid.setRecords(recordArray);
final SelectItem categoryItem = new SelectItem();
categoryItem.setName("materialId");
categoryItem.setPickListWidth(210);
categoryItem.setDisplayField("materialId");
categoryItem.setValueField("materialId");
categoryItem.setTitle("Material");
categoryItem.setOptionDataSource(getMaterialDataSource());
SelectItem itemName = new SelectItem() {
@Override
protected Criteria getPickListFilterCriteria() {
Integer materialId = (Integer) categoryItem.getValue();
Criteria criteria = new Criteria();
criteria.addCriteria("materialId", materialId);
return criteria;
}
};
itemName.setName("description");
itemName.setTitle("Item");
itemName.setDisplayField("description");
categoryItem.setValueField("description");
itemName.setPickListWidth(250);
itemName.setOptionDataSource(getMatAttrDataSource());
grid.setCanEdit(true);
first.setEditorProperties(categoryItem);
second.setEditorProperties(itemName);
grid.draw();
}
private static RestDataSource getMaterialDataSource() {
RestDataSource materialDS = new RestDataSource();
materialDS.setDataFormat(DSDataFormat.JSON);
materialDS.setID("materialDs");
materialDS.setDataURL("/vendor/getMaterials");
DataSourceField materialId = new DataSourceField("materialId", FieldType.INTEGER, "materialId");
materialId.setPrimaryKey(true);
DataSourceField materialField = new DataSourceField("materialCode", FieldType.TEXT, "materialCode");
DataSourceField descriptionField = new DataSourceField("description", FieldType.TEXT, "description");
materialDS.setFields(materialId, materialField, descriptionField);
materialDS.setJsonPrefix("");
materialDS.setJsonSuffix("");
return materialDS;
}
private static RestDataSource getMatAttrDataSource() {
RestDataSource materialAttrTypeDS = new RestDataSource();
materialAttrTypeDS.setID("materialAttrTypeDS");
materialAttrTypeDS.setDataFormat(DSDataFormat.JSON);
materialAttrTypeDS.setDataURL("/vendor/getMaterialAttrType");
DataSourceField materialId = new DataSourceField("materialId", FieldType.INTEGER, "materialId");
materialId.setForeignKey("materialDs.materialId");
materialId.setPrimaryKey(true);
DataSourceField descriptionField = new DataSourceField("description", FieldType.TEXT, "description");
materialAttrTypeDS.setFields(materialId, descriptionField);
materialAttrTypeDS.setJsonPrefix("");
materialAttrTypeDS.setJsonSuffix("");
return materialAttrTypeDS;
}
Comment