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

markus
  • 38,729
  • 23
  • 95
  • 139
Steel Plume
  • 2,190
  • 3
  • 24
  • 35

3 Answers3

1

You just need to refresh the table.

Alexey Romanov
  • 154,018
  • 31
  • 276
  • 433
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.

Devalex
  • 71
  • 6
1

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

viewer.setContentProvider(...);
viewer.setInput(...);
viewer.setComparator(myComparator);
myComparator.setColumn(colIndex);
viewer.refresh();
Sbodd
  • 10,779
  • 5
  • 38
  • 42