[英]How to add Celltable Row Dynamically at the end of table in GWT
目前我正在使用以下方法向我的CellTable添加一堆行
public void createTable(){
CellTable table = new CellTable(0,tableResource);
MyDataProvider dataprovider = new MyDataProvider(table);
setDataToList(myDataList);
}
public MyDataProvider extends ListDataProvider<MyModel>{
List<MyModel> dataList = new ArrayList<MyModel>();
public MyDataProvider(CellTable table){
this.addDataDisplay(table);
this.setList(dataList);
}
public void setDataToList(List<MyModel> models){
for(MyModel model: models){
dataList.add(model);
refresh();
}
}
}
我在表中沒有看到任何數據。 整個表仍然是空的。
您應該能夠將元素添加到ListDataProvider返回的列表中。 然后,在數據提供者上調用refresh()將更改推送到UI。
您還需要將表添加到數據提供者:
dataProvider.addDataDisplay(table);
http://www.gwtproject.org/javadoc/latest/com/google/gwt/view/client/ListDataProvider.html
我認為先更新單元格表的dataProvider,然后再調用refresh即可解決問題。
//add table to data provider do only the 1st time
dataProvider.addDataDisplay(cellTable);
//add new item to the list
dataProvider.getList().add(text);
//flush and refresh dataprovider for it to be updated
dataProvider.flush();
dataProvider.refresh();
//set celltable to new rowdata and row counts
cellTable.setRowData(0, dataProvider.getList());
cellTable.setRowCount(dataProvider.getList().size(), true);
//redraw the table with new data
celltable.redraw();
您可以使用此代碼
MyDataProvider.getList().add(new MyModel());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.