2011-02-09 59 views
3

假设数据使用RPCproxy从DataStore中检索,则在打开页面时使用ListStore填充到网格。如何重新加载GXT网格中的数据行?

然后,有一个表单添加一个实体,修改后它将反映GXT网格中的新列表和新添加的行。

如何重新加载网格?我尝试了Grid中的.reconfigure()方法,但没有工作。

回答

3

grid.getStore()。getLoader()。load();

更新:

首先您必须在代理之前提取电网,第二件事是改变你的RPC回调:

 

    public class PagingBeanModelGridExample extends LayoutContainer { 

    //put grid Class outside a method or declare it as a final on the begin of a method 
    Grid grid = null; 

    protected void onRender(Element parent, int index) { 
     super.onRender(parent, index); 

     RpcProxy> proxy = new RpcProxy>() { 

      @Override 
      public void load(Object loadConfig, final AsyncCallback> callback) { 
       //modification here - look that callback is overriden not passed through!! 
       service.getBeanPosts((PagingLoadConfig) loadConfig, new AsyncCallback>() { 

        public void onFailure(Throwable caught) { 
         callback.onFailure(caught); 
        } 

        public void onSuccess(PagingLoadResult result) { 
         callback.onSuccess(result); 
         //here you are reloading store 
         grid.getStore().getLoader().load(); 
        } 
       }); 
      } 
     }; 

     // loader 
     final BasePagingLoader> loader = new BasePagingLoader>(proxy, new BeanModelReader()); 

     ListStore store = new ListStore(loader); 
     List columns = new ArrayList(); 
     //... 
     ColumnModel cm = new ColumnModel(columns); 

     grid = new Grid(store, cm); 
     add(grid); 

    } 
}
+1

谢谢kospiotr。或者grid.reconfigure(store,cm)或者grid.getStore()。getLoader()。load();但我记得在rpc调用里面调用这个里面的成功方法(这就是我所缺少的):) – Lynard 2011-02-10 05:34:25

1

要显示新的数据网格,你真的需要重新加载网格? 您可以使用新数据创建新模型对象,并将其添加到ListStore。

假设您有一个CommentModel,它扩展了Comment模型commentStore的BaseModel和ListStore。

final ListStore<Commentmodel> commentStore = new ListStore<Commentmodel>(); 

//now call a rpc to load all available comments and add this to the commentStore. 
commentService.getAllComment(new AsyncCallback<List<Commentmodel>>() { 

    @Override 
    public void onFailure(Throwable caught) { 
    lbError.setText("data loading failure"); 

    } 

    @Override 
    public void onSuccess(List<Commentmodel> result) { 
    commentStore.add(result); 

    } 
    }); 

commentServiceAsyncService

现在,如果用户发表评论,只需要创建一个新的CommentModel对象与新的数据

CommentModel newData = new CommentModel('user name', 'message','date');

这增加了commentStore。

commentStore.add(newData);

希望这将成为你的目的。

但是,如果您确实需要重新加载整组数据,请再次调用该服务。在onSuccess方法首先清除commentStore然后添加结果。请记住,第一种方法更耗时。