简体   繁体   中英

How to add Celltable Row Dynamically at the end of table in GWT

Currently I am adding bunch of row to my CellTable using following method

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

}

I am not seeing any data in the table. The whole table is still empty.

You should be able to add elements to the list returned by ListDataProvider. Then, call refresh() on your data provider to push the changes to the UI.

You also need to add the table to the data prvider:

dataProvider.addDataDisplay(table);

http://www.gwtproject.org/javadoc/latest/com/google/gwt/view/client/ListDataProvider.html

I think an update to the celltable's dataProvider and then calling refresh should do the trick.

//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());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM