添加新行时,我想对 CellTable 中的行进行排序。
要标记 UI,我使用 UIBinder:
<g:HTMLPanel>
<c:CellTable pageSize='100' ui:field='myTable'/>
<c:SimplePager ui:field='myPager' location='CENTER'/>
</g:HTMLPanel>
在小部件中,我创建了一个表格和分页:
@UiField(provided=true) CellTable<myDTO> myTable;
SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
myPager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
myTable = new CellTable<myDTO>();
然后我安装了一个选择模型:
final NoSelectionModel<myDTO> selectionModel = new NoSelectionModel<myDTO>();
selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
public void onSelectionChange(SelectionChangeEvent event) {
clickedObject = selectionModel.getLastSelectedObject();
}
});
myTable.setPageSize(50);
myTable.setSelectionModel(selectionModel);
并添加了几列:
Column<myDTO, String> column1 = new Column<myDTO, String>(new TextCell()) {
@Override
public String getValue(myDTO data) {
return data.getSomeData1();
}
};
Column<myDTO, String> column2 = new Column<myDTO, String>(new TextCell()) {
@Override
public String getValue(myDTO data) {
return data.getSomeData2();
}
};
...
Column<myDTO, String> columnN = new Column<myDTO, String>(new TextCell()) {
@Override
public String getValue(myDTO data) {
return data.getSomeDataN();
}
};
myTable.addColumn(column1, "name of column1");
myTable.addColumn(column2, "name of column2");
...
myTable.addColumn(columnN, "name of columnN");
接下来,我创建AsyncDataProvider
:
AsyncDataProvider<myDTO> provider = new AsyncDataProvider<myDTO>() {
@Override
// is called when the table requests a new range of data
protected void onRangeChanged(HasData<myDTO> display) {
final int start = display.getVisibleRange().getStart();
final int lenght = display.getVisibleRange().getLength();
myService.findAll(new AsyncCallback<List<myDTO>>() {
public void onFailure(Throwable caught) {
// exception handling here
}
public void onSuccess(List<myDTO> data) {
updateRowCount(data.size(), true);
updateRowData(0, data);
}
});
}
};
provider.addDataDisplay(myTable);
如果我使用这种方法,则会将新行添加到表的末尾。
添加时我需要自动对行进行排序。
我该怎么做?