I want to sort rows in CellTable when adding new.
To markup UI I use UIBinder:
<g:HTMLPanel>
<c:CellTable pageSize='100' ui:field='myTable'/>
<c:SimplePager ui:field='myPager' location='CENTER'/>
</g:HTMLPanel>
In the widget I created a table and pagination:
@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>();
Then I installed a selection model:
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);
And added a few columns:
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");
Next, I create 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);
If I use this approach, then new rows are added to the end of the table.
I need to automatically sort rows when added.
How can I do it?
I would be very grateful for the information. Thanks to all.