I have a Gwt celltable. Clicking on the headers sorts the columns properly. But on page load the columns are not sorted by default. I want to make the right most column to be sorted when the page loads.
To clarify a couple of the existing answers... a cellTable
's sort list (as accessed by the getColumnSortList()
function) only determines how the state of the table's header, but does not actually sort any data.
As @z00bs suggested, it may be wise to sort the data externally, if possible. If you know that the data is going to be pre-sorted, then you should use the getColumnSortList().clear()
and getColumnSortList().push()
functions to communicate to your users how the data is sorted.
If, however, you want the CellTable to actually sort the data, you're going to need to trigger an event to force the CellTable to actually sort the constituent data client-side. To do this, you can use the state ColumnSortEvent.fire()
method, as such:
ColumnSortEvent.fire(myTable, myTable.getColumnSortList());
This will trigger an event which handles the sorting of the data based on the current state of the header. So you could set the desired initial sort state of the header first, and then execute this line to actually make the data ordering reflect the current sort state represented in the header.