PDA

View Full Version : how to set ColumnModel by rpc



charmw
29 Dec 2009, 8:49 PM
I am trying to set Grid's header by Rpc, something like:
class MyWindow extends window {

protected void onRender(Element parent, int index) {
super.onRender(parent, index);
final List configs = new ArrayList();
final ListStore store = new ListStore();

AsyncCallback callback = new AsyncCallback()
{
public void onSuccess(List result)
{
for(MyCol col : result){
ColumnConfig config = new ColumnConfig(col.getId(),col.getName,100);
configs.add(config);
}
}
public void onFailure(Throwable cause)
{}
};

service.getColModel(new callback);

....
....
....

service.getStore(new callback);

Grid grid = new Grid(stroe,cm);
this.add(grid);
}
}

Grid's contents can display, But header can't display...
Can somebody help me?

Thanks a lot

Love Yao
30 Dec 2009, 12:30 AM
I can not know what's wrong with your code(the way you using RPC I am confused ), just try my code.


public void onModuleLoad() {

final List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
ServiceAsync serviceServletAsync = GWT.create(Service.class);
final ColumnModel columnModel = new ColumnModel(configs);

final ListStore<BaseModel> store = new ListStore<BaseModel>();
final Grid<BaseModel> grid = new Grid<BaseModel>(store, columnModel);

serviceServletAsync.getSonglist(new AsyncCallback<List<String>>() {

@Override
public void onFailure(Throwable caught) {

}

@Override
public void onSuccess(List<String> result) {

for (String string : result) {

ColumnConfig columnConfig = new ColumnConfig();
columnConfig.setWidth(100);
columnConfig.setHeader(string);

configs.add(columnConfig);

}

RootPanel.get().add(grid);
}

});

}

Love Yao
30 Dec 2009, 12:43 AM
I know just coding this.add(grid) in function onSuccess(){}

,for RPC will delay.

charmw
30 Dec 2009, 1:49 AM
I can not know what's wrong with your code(the way you using RPC I am confused ), just try my code.


public void onModuleLoad() {

final List configs = new ArrayList();
ServiceAsync serviceServletAsync = GWT.create(Service.class);
final ColumnModel columnModel = new ColumnModel(configs);

final ListStore store = new ListStore();
final Grid grid = new Grid(store, columnModel);

serviceServletAsync.getSonglist(new AsyncCallback() {

@Override
public void onFailure(Throwable caught) {

}

@Override
public void onSuccess(List result) {

for (String string : result) {

ColumnConfig columnConfig = new ColumnConfig();
columnConfig.setWidth(100);
columnConfig.setHeader(string);

configs.add(columnConfig);

}

RootPanel.get().add(grid);
}

});

}
could you tell me your way ? how to set each columns header from database.

Arno.Nyhm
30 Dec 2009, 2:21 AM
you need to use Grid # reconfigure to change the store and the column model:


reconfigure

public void reconfigure(ListStore (http://www.extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/store/ListStore.html)<M (http://www.extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/widget/grid/Grid.html)> store,
ColumnModel (http://www.extjs.com/forum/../deploy/gxtdocs/com/extjs/gxt/ui/client/widget/grid/ColumnModel.html) cm) Reconfigures the grid to use a different Store and Column Model. The View will be bound to the new objects and refreshed.
Parameters:store - the new storecm - the new column model


note also, that your call to the server is a asychronus call - so your grid is created at first with a empty columnmodel - and adding something to this columnmodel not change the grid - you need to use reconfigure

sven
30 Dec 2009, 2:41 AM
If you want to create your grid based on serverside columndata, i would suggest to create the hole grid inside the onsuccess statement. This way the initial display will be faster, because it only has to draw the grid once