Hi,
I'm trying to dynamically show/hide a column of a ListGrid using the showIf mechanism.
There seems to be no effect for returning true or false in the following snippet.
The column showing this field appears on startup, and remains even after calls to grid.refreshFields().
Technincal details:
SmartGWT 2.1
IE 8.0.7600, FF 3.6.12
Following is the full example code - I was expecting that pressing the "Toggle" button would make the column show/hide, but it doesn't.
Any insight on what I'm missing here ?
Thanks!
Lior
I'm trying to dynamically show/hide a column of a ListGrid using the showIf mechanism.
There seems to be no effect for returning true or false in the following snippet.
The column showing this field appears on startup, and remains even after calls to grid.refreshFields().
Code:
listGridField.setShowIfCondition(new ListGridFieldIfFunction() { @Override public boolean execute(ListGrid grid, ListGridField field, int fieldNum) { // return true; return false; } });
SmartGWT 2.1
IE 8.0.7600, FF 3.6.12
Following is the full example code - I was expecting that pressing the "Toggle" button would make the column show/hide, but it doesn't.
Any insight on what I'm missing here ?
Thanks!
Lior
Code:
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridFieldIfFunction; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.widgets.layout.VLayout; /** * */ public class Test implements EntryPoint { private ListGrid grid; private IButton button; private Label label; private boolean isShowingDescription; private ListGrid getGrid() { final ListGrid grid = new ListGrid(); grid.setWidth(500); grid.setHeight(224); grid.setShowAllRecords(true); grid.setCanEdit(false); ListGridField nameField = getNameField(); ListGridField descField = getDescriptionField(); grid.setFields(nameField, descField); grid.setData(getDummyData()); return grid; } private ListGridField getDescriptionField() { isShowingDescription = true; ListGridField descField = new ListGridField("desc", "Description"); descField.setShowIfCondition(new ListGridFieldIfFunction() { @Override public boolean execute(ListGrid grid, ListGridField field, int fieldNum) { label.setContents(isShowingDescription ? "Showing description" : "Hiding description"); return isShowingDescription; } }); return descField; } private IButton getButton() { IButton btn = new IButton("Toggle"); btn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { isShowingDescription = !isShowingDescription; grid.refreshFields(); grid.redraw(); } }); return btn; } // // // private ListGridField getNameField() { return new ListGridField("name", "Name"); } private Label getLabel() { Label label = new Label(); label.setContents(isShowingDescription ? "Showing description" : "Hiding description"); return label; } private ListGridRecord[] getDummyData() { ListGridRecord[] data = new ListGridRecord[]{ new Item("One", "Traditionally the 1st natural number"), new Item("Two", "Better than one.") }; return data; } private class Item extends ListGridRecord { public Item(String name, String desc) { setAttribute("name", name); setAttribute("desc", desc); } } public void onModuleLoad() { VLayout layout = new VLayout(); grid = getGrid(); button = getButton(); label = getLabel(); layout.addMember(grid); layout.addMember(label); layout.addMember(button); RootPanel.get().add(layout); } }
Comment