I've a grid ,but I want only 2 columns with option to sort, as I do that?
RowSorter newSorter = new TableRowSorter(table.getModel());
newSorter.setSortKeys(sortKeys);
table.setRowSorter(newSorter);
I used this
I've a grid ,but I want only 2 columns with option to sort, as I do that?
RowSorter newSorter = new TableRowSorter(table.getModel());
newSorter.setSortKeys(sortKeys);
table.setRowSorter(newSorter);
I used this
Copyright © 2021 Jogjafile Inc.
You virtually had the answer in your hands...
Basically, the
setSortKeysmethod gets called whenever you (or the table) wants to change the sorting (direction or column).What you can do is override the
TabelRowSorter#setSortKeysmethod and filter the list as you see fitNow, I'm pretty sure, it wouldn't take much to extend this concept to a configurable level, so you could add "valid" column indices...
You could also go a step further and only allow selected columns to be sorted in a single direction...