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. Ple开发者_如何学JAVAase can you help me? Tnx
You just need to refresh the table.
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.
Building off Devalex's answer, the following worked for me:
viewer.setContentProvider(...);
viewer.setInput(...);
viewer.setComparator(myComparator);
myComparator.setColumn(colIndex);
viewer.refresh();
精彩评论