假設數據使用RPCproxy從DataStore中檢索,則在打開頁面時使用ListStore填充到網格。如何重新加載GXT網格中的數據行?
然後,有一個表單添加一個實體,修改後它將反映GXT網格中的新列表和新添加的行。
如何重新加載網格?我嘗試了Grid中的.reconfigure()方法,但沒有工作。
假設數據使用RPCproxy從DataStore中檢索,則在打開頁面時使用ListStore填充到網格。如何重新加載GXT網格中的數據行?
然後,有一個表單添加一個實體,修改後它將反映GXT網格中的新列表和新添加的行。
如何重新加載網格?我嘗試了Grid中的.reconfigure()方法,但沒有工作。
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);
}
}
要顯示新的數據網格,你真的需要重新加載網格? 您可以使用新數據創建新模型對象,並將其添加到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);
}
});
commentService
是AsyncService
。
現在,如果用戶發表評論,只需要創建一個新的CommentModel
對象與新的數據
CommentModel newData = new CommentModel('user name', 'message','date');
這增加了commentStore。
commentStore.add(newData);
希望這將成爲你的目的。
但是,如果您確實需要重新加載整組數據,請再次調用該服務。在onSuccess
方法首先清除commentStore然後添加結果。請記住,第一種方法更耗時。
謝謝kospiotr。或者grid.reconfigure(store,cm)或者grid.getStore()。getLoader()。load();但我記得在rpc調用裏面調用這個裏面的成功方法(這就是我所缺少的):) – Lynard 2011-02-10 05:34:25