Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "sorter" to the SSDataGrid #7

Open
bpangburn opened this issue Dec 10, 2020 · 1 comment · Fixed by #174
Open

Add a "sorter" to the SSDataGrid #7

bpangburn opened this issue Dec 10, 2020 · 1 comment · Fixed by #174

Comments

@bpangburn
Copy link
Owner

2005-03-10, Prasanth Pasala: https://sourceforge.net/p/swingset/feature-requests/21/

As suggested in this thread on the forums, we need to investigate adding a table sorter to the SSDataGrid:
https://sourceforge.net/forum/message.php?msg_id=3038707

Amit provided the following info on how to implement this:

Also, I am using a TableSorter given by the sun
JTable table = (JTable) viewport.getView();
//Encapsulate the table model by TableSorter to add sorting functionality
TableSorter sorter = new TableSorter(table.getModel());
table.setModel(sorter);
sorter.setTableHeader(table.getTableHeader());

Is the additional comma due to the TableSorter, the code for the table sorter can be found at
http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/TableSorter.java (dead link)

Possibly:
https://docs.oracle.com/javase/tutorial/uiswing/examples/components/TableSorterDemoProject/src/components/TableSorter.java
From:
https://docs.oracle.com/javase/tutorial/uiswing/components/table.html

@errael
Copy link
Contributor

errael commented Feb 18, 2023

Original comment from JDK 1.2! Try SSDataGrid sorting from https://github.com/bpangburn/swingset/tree/Grid Example5

@bpangburn @prasanthreddy-git weighing in and additional considerations appreciated

As of 2023/02/18

Added SSDataGrid.setSorting(boolean) to enable/disable sorting

Starts with sorting enabled, click column header to sort, and Swing defaults

  • Up to 3 sort keys
  • No custom comparators

Grid specific behavior

  • When the insert row is displayed, no sorting; when the insert row is taken down the previous sort is reestablished
  • When sorting is disabled, the sorting is forgotten and is fresh (null sort keys) when re-enabled

Possible additions/changes

  • Have column header clicking cycle through an additional state "no sort"
    Currently no way to turn off sort with column clicking.
  • Are custom comparators needed?

Note: The Swing table's sorting has support for filtering, there's #127 about filtering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants