Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Table Sorting (I know it is a pain)

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I wanted to implement a simple sorting for the JTable (I have cursed sun at least 1,000,000 times for not providing that)

I implemented a simple single level sorting taking help from the TableSorter from the Examples. But there is a small complication.

when there are many rows with same values i just leave the order as it is. But now if i sort it based on column 1 first and then go to column 2 then the order is different and if i go to column 3 first and then to column 2 then t order is different

Please let me know if that is an issue?
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, your problem must be that you are not extending your own TableModel. In my implementation I extended AbstracTableModel and instead of using a Vector of String objects with independent columns I use a List of Hotels [List<Hotel>] as the model of the TableModel.

Therefore every line in my TableModel is whole value object.

Early in my implementation I created Comparators for all the Hotel fields (name, location, rate, size, date, etc).

So, in my TableModel I do not order a particular column, I order the whole collection of Hotels using a Comparator. Somewhat like:



That sorts my List<Hotel> using a particular comparator and evidently all the colums are displayed accordinginly in the JTable.
[ October 21, 2006: Message edited by: Edwin Dalorzo ]
 
Sam Codean
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Edwin,
I too have done something similar to what you are telling. But the problem that i am facing i will explain
Suppose there are three rows (simplified though)


So you see that after the step 2 of both the variations even though i am sorting the column 2 and it indeed is sorted but yet the rows with the same City will not be having the same order as it depends on which column was selected earlier.

I was wanting to know if that is fine as long as sorting is done correctly on the column 2
[ October 21, 2006: Message edited by: Sam Codean ]
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic