2011-02-09 17 views
3

データがRPCproxyを使用してデータストアから取得すると仮定すると、ページを開くとListStoreを使用してグリッドに移入します。GXTグリッドでデータ行を再読み込みする方法は?

エンティティを追加するフォームがあり、変更後に、新しい追加された行を含むGXTグリッドの新しいリストが反映されます。

グリッドをリロードするにはどうすればよいですか?グリッドで.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();私が紛失しているもの) – Lynard

+0

onSuccess()を呼び出すことによって無限ループが発生しているようです。 onSuccess()によってgrid.getStore()が呼び出されました。 getLoader()。load(); onSuccess()を再帰的に呼び出します。 –

1

グリッドに新しいデータを表示するには、あなたが本当に必要なのですグリッドをリロードするには? 新しいデータで新しいモデルオブジェクトを作成し、これをListStoreに追加することができます。

コメントモデルcommentStoreのBaseModelとListStoreを拡張するCommentModelがあるとします。

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 newData = new CommentModel('user name', 'message','date');

で新しいCommentModelオブジェクトを作成し、commentStoreにこれを追加します。

commentStore.add(newData);

希望これはあなたの目的を果たすだろう。

本当にデータセット全体をリロードする必要がある場合は、サービスを再度呼び出してください。 onSuccessメソッドでは、最初にcommentStoreをクリアしてから結果を追加します。これは第1のアプローチよりも時間がかかることを忘れないでください。

関連する問題