1. #1
    Ext User
    Join Date
    Dec 2009
    Posts
    2
    Vote Rating
    0
    charmw is on a distinguished road

      0  

    Default how to set ColumnModel by rpc

    how to set ColumnModel by rpc


    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<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    final ListStore<BaseModel> store = new ListStore<BaseModel>();

    AsyncCallback callback = new AsyncCallback()
    {
    public void onSuccess(List<MyCol> 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

  2. #2
    Ext User
    Join Date
    Nov 2009
    Posts
    38
    Vote Rating
    0
    Love Yao is on a distinguished road

      0  

    Default


    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);
    }

    });

    }

  3. #3
    Ext User
    Join Date
    Nov 2009
    Posts
    38
    Vote Rating
    0
    Love Yao is on a distinguished road

      0  

    Default


    I know just coding this.add(grid) in function onSuccess(){}

    ,for RPC will delay.

  4. #4
    Ext User
    Join Date
    Dec 2009
    Posts
    2
    Vote Rating
    0
    charmw is on a distinguished road

      0  

    Question


    Quote Originally Posted by Love Yao View Post
    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);
    }

    });

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

  5. #5
    Ext User
    Join Date
    Sep 2008
    Location
    Germany
    Posts
    961
    Vote Rating
    0
    Arno.Nyhm is on a distinguished road

      0  

    Default


    you need to use Grid # reconfigure to change the store and the column model:

    reconfigure

    public void reconfigure(ListStore<M> store,
    ColumnModel 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
    This forum needs your help: you got hints from the community and now you have fixed your code? dont just reply with "now its fixed" or "i found the error"! please take the time to post also an detailed answer with the working code.

    GreaseMonkey Script for a GXT-only Forum: it hides ExtJs here: New Posts • Search Results • Advanced Search form • Category overview http://www.extjs.com/forum/showthrea...041#post410041

  6. #6
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    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