Sorting PagedDataTable
Having a MaterialDataTable with a MaterialDataPager I would like to sort my data. Which works in the way, that the data on the current page is sorted. What I had in mind though, would be that all data in my table gets sorted. I tried a couple of approaches till I found one that actually does what I had in mind. I wrote my own SortableListDataSource, which sorts the data on every call of the load-method.
final SortContext<T> sortContext = loadConfig.getSortContext();
if (sortContext != null) {
Comparator<? super RowComponent<T>> sortComparator = sortContext.getSortColumn().getSortComparator();
if (sortComparator != null) {
data.sort((o1, o2) -> sortComparator.compare(getRowComponent(o1), getRowComponent(o2)) * getSortDirection(sortContext));
}
}
Now I needed to add a ColumnSortHandler, which triggers the doLoad-method of the pager.
addColumnSortHandler(event -> {
pager.gotoPage(pager.getCurrentPage());
});
It's working but it's not what I would call a nice solution. So I'm either missing something here, which is very likely or this scenario hasn't been addressed yet.
Any advice on that matter is appreciated.
I would also like to know if their is a proper way of sorting all the data, rather than just the visible data.
Same here. This seems like a bug to me -- column sorting should apply to all rows in the table, not just the rows visible on the current page.
Is there a timeframe when this issue going to be addressed? I would also expect sorting all rows is the correct behaviour.
This is likely a bug, I will look into it as soon as possible. Thanks for the report guys.