TableViewer, defining an initial sorting order has no effect on data
Asked Answered
R

3

6

pratically I build up a tableviewer as usual, but initially it does not sort all the rows according the column defined for sorting.

The code I am using:

viewer.getTable().setSortColumn(viewer.getTable().getColumn(4));
viewer.getTable().setSortDirection(SWT.UP);

Only after clicking manually the column #4 I obtain the correct order, otherwise it follows exactly the "insert order" of the object list linked to the ViewContentProvider. Please can you help me? Tnx

Rahal answered 14/11, 2009 at 4:21 Comment(0)
E
1

You just need to refresh the table.

Ethelstan answered 24/1, 2013 at 13:22 Comment(0)
E
1

Just had the same problem.

When using ... tableViewer.setComparator(comparator) ... the above code is ignored.

You have to set manually the initial sort column index in the extended ViewerComparator.

Expansion answered 9/9, 2015 at 15:44 Comment(0)
J
1

Building off Devalex's answer, the following worked for me:

viewer.setContentProvider(...);
viewer.setInput(...);
viewer.setComparator(myComparator);
myComparator.setColumn(colIndex);
viewer.refresh();
Juniorjuniority answered 31/10, 2016 at 4:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.