GwtMaterialDesign / gwt-material-table

A complex table component designed for the material design specifications
https://gwtmaterialdesign.github.io/gmd-table-demo/
Apache License 2.0
27 stars 31 forks source link

Sorting PagedDataTable #133

Open fisimatenten opened 6 years ago

fisimatenten commented 6 years ago

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.

ichigo92 commented 6 years ago

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

brichbe commented 6 years ago

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.

kkrupka commented 5 years ago

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

BenDol commented 5 years ago

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