- SmartGWT 5.1 power edition - v9.1p_2014-06-24/PowerEdition Deployment 2014-06-24
- Google Chrome Version 49.0.2623.87 (64-bit)
In our usecase these criteria need to be different:
- ListGrid: filter out inactive records in order to be able to only select active records
- DataSourceField: allow using the FilterBuilder with inactive records
Test case:
Code:
package test.client;
import com.google.gwt.core.client.EntryPoint;
import com.smartgwt.client.data.AdvancedCriteria;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.types.OperatorId;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.form.FilterBuilder;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.FormItem;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridEditorContext;
import com.smartgwt.client.widgets.grid.ListGridEditorCustomizer;
import com.smartgwt.client.widgets.grid.ListGridField;
import com.smartgwt.client.widgets.layout.VLayout;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class Test implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
VLayout vlayout = new VLayout();
vlayout.setWidth100();
vlayout.setHeight100();
// Setting picklist criteria on datasource editor type, in order to
// be able to filter on both active and inactive records in the FilterBuilder
ContentDS.getInstance().getField("cntn_fk_contentType").setEditorProperties(createContentTypeCombobox(new Criteria()));
Button button = new Button("editFilter");
vlayout.addMember(button);
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
FilterBuilder filterBuilder = new FilterBuilder();
filterBuilder.setDataSource(ContentDS.getInstance());
Window window = new Window();
window.setWidth(800);
window.setHeight(300);
window.addItem(filterBuilder);
window.show();
}
});
ListGrid listGrid = new ListGrid();
listGrid.setCanEdit(true);
listGrid.setAutoFetchData(true);
listGrid.setDataSource(ContentDS.getInstance());
listGrid.setFields(new ListGridField("cntn_id"), new ListGridField("cntn_fk_contentType"));
listGrid.setEditorCustomizer(new ListGridEditorCustomizer() {
@Override
public FormItem getEditor(ListGridEditorContext context) {
if ("cntn_fk_contentType".equals(context.getEditField().getName())) {
// Setting picklist criteria on listGrid editor type, in order to
// be able to filter only active records
return createContentTypeCombobox(new AdvancedCriteria("cntp_active", OperatorId.EQUALS, true));
} else {
return context.getDefaultProperties();
}
}
});
vlayout.addMember(listGrid);
vlayout.draw();
}
private ComboBoxItem createContentTypeCombobox(Criteria criteria) {
ComboBoxItem item = new ComboBoxItem("cntn_fk_contentType", "cntn_fk_contentType");
item.setOptionDataSource(ContentTypeDS.getInstance());
item.setPickListFields(new ListGridField("cntp_pk"), new ListGridField("cntp_active"));
item.setPickListCriteria(criteria);
return item;
}
}
Code:
package test.client;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;
public class ContentDS extends DataSource {
private static ContentDS instance = null;
public static ContentDS getInstance() {
if (instance == null) {
instance = new ContentDS("Content");
}
return instance;
}
private ContentDS(String id) {
setID(id);
setClientOnly(true);
DataSourceIntegerField pkField = new DataSourceIntegerField("cntn_pk");
pkField.setHidden(true);
pkField.setPrimaryKey(true);
DataSourceTextField idField = new DataSourceTextField("cntn_id");
DataSourceIntegerField contentTypeField = new DataSourceIntegerField("cntn_fk_contentType");
setFields(pkField, idField, contentTypeField);
setTestData(
new ContentRecord(1, "001", 11),
new ContentRecord(2, "002", 11),
new ContentRecord(3, "003", 22),
new ContentRecord(4, "004", 33));
}
private class ContentRecord extends Record {
public ContentRecord(Integer pk, String name, Integer contentType) {
setAttribute("cntn_pk", pk);
setAttribute("cntn_id", name);
setAttribute("cntn_fk_contentType", contentType);
}
}
}
Code:
package test.client;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.data.fields.DataSourceBooleanField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
public class ContentTypeDS extends DataSource {
private static ContentTypeDS instance = null;
public static ContentTypeDS getInstance() {
if (instance == null) {
instance = new ContentTypeDS("ContentType");
}
return instance;
}
private ContentTypeDS(String id) {
setID(id);
setClientOnly(true);
DataSourceIntegerField pkField = new DataSourceIntegerField("cntp_pk");
pkField.setPrimaryKey(true);
DataSourceBooleanField activeField = new DataSourceBooleanField("cntp_active");
setFields(pkField, activeField);
setTestData(
new ContentRecord(11, true),
new ContentRecord(22, true),
new ContentRecord(33, false),
new ContentRecord(44, false));
}
private class ContentRecord extends Record {
public ContentRecord(Integer pk, boolean active) {
setAttribute("cntp_pk", pk);
setAttribute("cntp_active", active);
}
}
}
Comment