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
  • 40,136
  • 23
  • 97
  • 142
Steel Plume
  • 2,260
  • 3
  • 26
  • 35

3 Answers3

1

You just need to refresh the table.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
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
  • 11,279
  • 6
  • 41
  • 42