gwt-material-table icon indicating copy to clipboard operation
gwt-material-table copied to clipboard

Sorting PagedDataTable

Open fisimatenten opened this issue 8 years ago • 4 comments

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.

fisimatenten avatar Jan 22 '18 13:01 fisimatenten

I would also like to know if their is a proper way of sorting all the data, rather than just the visible data.

ichigo92 avatar Aug 13 '18 05:08 ichigo92

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.

brichbe avatar Oct 10 '18 16:10 brichbe

Is there a timeframe when this issue going to be addressed? I would also expect sorting all rows is the correct behaviour.

kkrupka avatar Nov 26 '18 15:11 kkrupka

This is likely a bug, I will look into it as soon as possible. Thanks for the report guys.

BenDol avatar Nov 26 '18 15:11 BenDol