Search code examples
gwtsortingcelltable

Gwt celltable invoke sort on a column


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.


Solution

  • You can use the getColumnSortList() and push the column you want to sort by, as such:

    dataGrid.getColumnSortList().push(columnToSortBy);
    

    The table will be sorted by the given column in ascending order.

    Calling this method twice, will trigger a check to tests if the given column already pushed to the list, and if so it will gets sorted in descending order, so to get the table sorted by the column in descending order use:

    dataGrid.getColumnSortList().push(columnToSortBy);
    dataGrid.getColumnSortList().push(columnToSortBy);
    

    Behind the scene, The column is pushed to an inner list in the table called ColumnSortList to position 0. The same list is updated on each column header click.

    Make sure you call this method after you initialized the column.