Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 205
Steel Plume Avatar asked Nov 14 '09 04:11

Steel Plume


3 Answers

You just need to refresh the table.

like image 156
Alexey Romanov Avatar answered Oct 27 '22 10:10

Alexey Romanov


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.

like image 42
Devalex Avatar answered Oct 27 '22 09:10

Devalex


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

viewer.setContentProvider(...);
viewer.setInput(...);
viewer.setComparator(myComparator);
myComparator.setColumn(colIndex);
viewer.refresh();
like image 45
Sbodd Avatar answered Oct 27 '22 09:10

Sbodd