PDA

View Full Version : [OPEN] [CLOSED] ColumnConfig.setHidden does not appear to work after initial rendering



bigmountainben
13 May 2009, 10:18 AM
Calling ColumnConfig's setHidden method does not work once a Grid has been rendered. It works if its called before, but not if it's called after. The documentation does not make mention of the fact that it only works before rendering.

Calling ColumnModel's setHidden(int,boolean) is a workaround.

This occurs under GXT2.0m1 (built as of 5/9), GWT 1.6.4 on Mac OS 1.5.6 under hosted mode (WebKit engine) and on FF3.

This is the reproducible test case:




import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.FieldEvent;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.form.CheckBox;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.RootPanel;

import java.util.Arrays;

/**
* Created by IntelliJ IDEA.
* User: br
* Date: May 8, 2009
* Time: 11:26:17 AM
* To change this template use File | Settings | File Templates.
*/
public class Test implements EntryPoint {

public void onModuleLoad() {
RootPanel.get().add(new TestGrid());
}

class TestGrid extends LayoutContainer {

Grid grid;
ColumnConfig fooColumn;
ColumnConfig barColumn;

TestGrid() { }

@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
final CheckBox cb = new CheckBox();
cb.addListener(Events.OnClick, new Listener<FieldEvent>() {
public void handleEvent(FieldEvent fe) {
boolean value = ((CheckBox)fe.getField()).getValue();
fooColumn.setHidden(value);
GWT.log("calling setHidden on fooColumn with " + value, null);
}
});
ToolBar tb = new ToolBar() {{
add(cb);
}};

ListStore<ModelData> store = new ListStore<ModelData>();
store.add(new BaseModelData() {{ set("foo", "a foo"); set("bar", "a bar"); }});
store.add(new BaseModelData() {{ set("foo", "b foo"); set("bar", "b bar"); }});
store.add(new BaseModelData() {{ set("foo", "c foo"); set("bar", "c bar"); }});

fooColumn = new ColumnConfig("foo", "Foo", 100);
barColumn = new ColumnConfig("bar", "Bar", 100);
grid = new Grid(store, new ColumnModel(Arrays.asList(fooColumn, barColumn)));

add(tb);
add(grid);
}
}
}

sven
13 May 2009, 12:17 PM
Your approsch is wrong. You set it on the config.

Your are looking for:


columnModel.setHidden(colindex,true)

bigmountainben
13 May 2009, 4:01 PM
Thanks Sven.

It's even documented in ColumnConfig:

/**
* A column config for a column in a column model.
*
* <p /> The column config is a configuration object that should only be used
* when creating a column model. After the column model is created, any changes
* should be made to the column model, not the column config.
*/

bimjulien
24 Jan 2011, 8:13 AM
Hi guys,

It seems it doesn't work on Internet Explorer. Is it right ?

Thanks