How to make sure "cellTable.getColumnSortList().push" sort column Descending?

StackOverflow https://stackoverflow.com/questions/23462211

  •  15-07-2023
  •  | 
  •  

Question

I want myCellTable to sort qtyColumn descending. That is the ones with highest qty will be on top.

myCellTable.getColumnSortList().push(qtyColumn);
myCellTable.getColumnSortList().push(qtyColumn);
//someone said we have to do the push twice. I did but it still sort Asc. 
So I think the above code doesn't seem elegant

I just need 1 simple code that guarantee that the table will show data with qty column sorted desc.

So, How to show table with qty column sorted desc?

Note: I found this public ColumnSortList.ColumnSortInfo(Column<?,?> column, boolean ascending) but don't know how to use it?

Tried many way but it didn't work.

myCellTable.getColumnSortList().push(new ColumnSortInfo(qtyColumn, false)); // not working

 //this is also not working
 ColumnSortInfo sortInfo = myCellTable.getColumnSortList().push(qtyColumn);
 if (sortInfo.isAscending()) {
        myCellTable.getColumnSortList().push(qtyColumn);

 }
Was it helpful?

Solution 2

this seems to work, not sure if it has any problem:

table.getColumnSortList().clear();
table.getColumnSortList().push(column);
table.getColumnSortList().push(column);                 
ColumnSortEvent.fire(table, table.getColumnSortList());

OTHER TIPS

Workaround : If nothing is working then simply pass a already sorted List to the CellTable or ListDataProvider as per your initial sorting.

use Collections.sort()

Its working perfectly for me.

Sample code : (sort by name descending)

    Collections.sort(contactList,new Comparator<Contact>() {

        @Override
        public int compare(Contact o1, Contact o2) {
            return o2.name.compareTo(o1.name);
        }
    });

    // Create a data provider.
    ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>(contactList);

    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);

Find a sample code below for sorting on header column's click.

Try calling

setVisibleRangeAndClearData(Range range, boolean forceRangeChangeEvent)

on cell table with second parameter true to force RangeChangeEvent right after push call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top