Hello,
I found 2 bugs in Smartgwt Dropdown Tree.
1) SelectItem. fetchData() causes JavaScriptException (TypeError): data._invalidateCache is not a function.
As I understand the _invalidateCache function is missing in ResultTree.
2) When setMultiple(true) and setMultipleAppearance(MultipleAppearance.PICKLIST) are set for Dropdown Tree, select item value is not updated after selection change. I found workaround but this really should be fixed.
Smart GWT version 12.0
Test code:
I found 2 bugs in Smartgwt Dropdown Tree.
1) SelectItem. fetchData() causes JavaScriptException (TypeError): data._invalidateCache is not a function.
As I understand the _invalidateCache function is missing in ResultTree.
2) When setMultiple(true) and setMultipleAppearance(MultipleAppearance.PICKLIST) are set for Dropdown Tree, select item value is not updated after selection change. I found workaround but this really should be fixed.
Smart GWT version 12.0
Test code:
package test2.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.types.MultipleAppearance;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TestTreeSelect2 implements EntryPoint {
private int counter = 10;
/**
* This is the entry point method.
*/
public void onModuleLoad() {
DataSource ds = new TestDS();
final DynamicForm form = new DynamicForm();
form.setWidth(500);
ListGridField nameField = new ListGridField("name");
ListGridField emailField = new ListGridField("id");
ListGrid pickListProperties = new ListGrid();
pickListProperties.setAutoFitFieldWidths(true);
SelectItem item = new SelectItem("manager");
item.setTitle("Choose Manager");
item.setOptionDataSource(ds);
item.setDataSetType("tree");
item.setAutoOpenTree("all");
item.setValueField("id");
item.setWrapTitle(false);
item.setPickListWidth(350);
item.setPickListFields(nameField, emailField);
item.setPickListProperties(pickListProperties);
item.setMultiple(true);
item.setMultipleAppearance(MultipleAppearance.PICKLIST);
ButtonItem btn = new ButtonItem("fetchData");
btn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
item.fetchData();
}
});
ButtonItem addBtn = new ButtonItem("AddItem");
addBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ListGridRecord rec = new ListGridRecord();
rec.setAttribute("id", "Test" + counter);
rec.setAttribute("name", "Test" + counter);
rec.setAttribute("isFolder", false);
ds.addData(rec);
counter++;
}
});
form.setItems(item, btn, addBtn);
form.draw();
}
private static class TestDS extends DataSource {
public TestDS() {
setID("TestDS");
setDataFormat(DSDataFormat.JSON);
DataSourceField idField = new DataSourceField("id", FieldType.TEXT);
idField.setPrimaryKey(true);
DataSourceField parentidField = new DataSourceField("parentid", FieldType.TEXT);
parentidField.setForeignKey("id");
DataSourceField nameField = new DataSourceField("client", FieldType.TEXT);
DataSourceField totalField = new DataSourceField("total", FieldType.FLOAT);
DataSourceField crm_institutionField = new DataSourceField("crm_institution", FieldType.TEXT);
setFields(idField, parentidField, nameField, totalField, crm_institutionField);
setTitleField("client");
setDataURL("./data.json");
setClientOnly(true);
}
}
}
Json:
[
{
"id": "Test0",
"name": "Test0"
},
{
"id": "HT",
"name": "HT"
},
{
"id": "HT|Paris",
"name": "Paris",
"parentid": "HT",
"isFolder" : false
},
{
"id": "HT|UK",
"name": "UK",
"parentid": "HT",
"isFolder" : false
},
{
"id": "HT|US",
"name": "US",
"parentid": "HT",
"isFolder" : false
},
{
"id": "HT|Madrid",
"name": "Madrid",
"parentid": "HT"
},
{
"id": "Test",
"name": "Test"
},
{
"id": "Test2",
"name": "Test2"
}
]
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.DataSourceField;
import com.smartgwt.client.types.DSDataFormat;
import com.smartgwt.client.types.FieldType;
import com.smartgwt.client.types.MultipleAppearance;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.SelectItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.grid.ListGridRecord;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TestTreeSelect2 implements EntryPoint {
private int counter = 10;
/**
* This is the entry point method.
*/
public void onModuleLoad() {
DataSource ds = new TestDS();
final DynamicForm form = new DynamicForm();
form.setWidth(500);
ListGridField nameField = new ListGridField("name");
ListGridField emailField = new ListGridField("id");
ListGrid pickListProperties = new ListGrid();
pickListProperties.setAutoFitFieldWidths(true);
SelectItem item = new SelectItem("manager");
item.setTitle("Choose Manager");
item.setOptionDataSource(ds);
item.setDataSetType("tree");
item.setAutoOpenTree("all");
item.setValueField("id");
item.setWrapTitle(false);
item.setPickListWidth(350);
item.setPickListFields(nameField, emailField);
item.setPickListProperties(pickListProperties);
item.setMultiple(true);
item.setMultipleAppearance(MultipleAppearance.PICKLIST);
ButtonItem btn = new ButtonItem("fetchData");
btn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
item.fetchData();
}
});
ButtonItem addBtn = new ButtonItem("AddItem");
addBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
ListGridRecord rec = new ListGridRecord();
rec.setAttribute("id", "Test" + counter);
rec.setAttribute("name", "Test" + counter);
rec.setAttribute("isFolder", false);
ds.addData(rec);
counter++;
}
});
form.setItems(item, btn, addBtn);
form.draw();
}
private static class TestDS extends DataSource {
public TestDS() {
setID("TestDS");
setDataFormat(DSDataFormat.JSON);
DataSourceField idField = new DataSourceField("id", FieldType.TEXT);
idField.setPrimaryKey(true);
DataSourceField parentidField = new DataSourceField("parentid", FieldType.TEXT);
parentidField.setForeignKey("id");
DataSourceField nameField = new DataSourceField("client", FieldType.TEXT);
DataSourceField totalField = new DataSourceField("total", FieldType.FLOAT);
DataSourceField crm_institutionField = new DataSourceField("crm_institution", FieldType.TEXT);
setFields(idField, parentidField, nameField, totalField, crm_institutionField);
setTitleField("client");
setDataURL("./data.json");
setClientOnly(true);
}
}
}
Json:
[
{
"id": "Test0",
"name": "Test0"
},
{
"id": "HT",
"name": "HT"
},
{
"id": "HT|Paris",
"name": "Paris",
"parentid": "HT",
"isFolder" : false
},
{
"id": "HT|UK",
"name": "UK",
"parentid": "HT",
"isFolder" : false
},
{
"id": "HT|US",
"name": "US",
"parentid": "HT",
"isFolder" : false
},
{
"id": "HT|Madrid",
"name": "Madrid",
"parentid": "HT"
},
{
"id": "Test",
"name": "Test"
},
{
"id": "Test2",
"name": "Test2"
}
]
Comment