Anna
Anna

Reputation: 1627

JTable model does not refrech after sorting by columns

I have a problem when trying to preview a row after sorting a column.

for example : this is my table before sorting it

enter image description here

when i try to sort by the second column, i get this result which is normal:

enter image description here

but when i try to preview details of the second line with the ID (A199) i get the ones of (A195) which it was previously the second line before the sort. (i've added an action when doubleclicking a row to preview row details )

so my hypothesis is that the table model is not updated properly, this is what i've tried :

TableRowSorter<PersonneMoraleSearchTableModel> sorter = new TableRowSorter<PersonneMoraleSearchTableModel>(model);
jTable.setRowSorter(sorter);
List<RowSorter.SortKey> sortKeys = new ArrayList<SortKey>(25);
sortKeys.add(new RowSorter.SortKey(1, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
sorter.setSortsOnUpdates(true);

any help would be appreciated !

Upvotes: 1

Views: 746

Answers (1)

bracco23
bracco23

Reputation: 2211

As the doc says TableRowSorter only cares about the view and not the model of the table.

Some function are used in the description of the doc to convert the indexes between model and view in case a sorting/filtering function (as in your case) is used.

Try changing the ActionListener to use those function and the problem should be fixed.

Upvotes: 2

Related Questions