• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

B&S using a sorted column table to display the records? How many of you have done this?

 
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Planning on doing a table where the user can sort the columns in natural sorting order by each field (except the owner ID). Is this a popular choice?
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hum... I guess not, since it isn't really a requirement, you know... I myself didn't do it
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Yucca,
I initially implemented it because it is something useful and very common for the tables. Later I
noticed that I must implement a custom comparator for the currency field that contains the $ sign (in my example)
As the currency was not specified, I did not want to make things more complicated than they are.
Greetings,
Liviu
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorting rows and columns are not hard with tables. But I found that out at the beginning, when I sorted mine the table row and my record number matching screw up. Oh I was using the table setAutoRowSorter(true) thing.

At the end I didn't bother with sorting. And a column model is needed to not screw up the record number. It's your choice.
 
Roberto Perillo
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's because the rows in the table are sorted, but the data in the table model is still in the same order... in the end of the day, it is a waste of time, since it isn't really required.
 
Liviu Carausu
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:Sorting rows and columns are not hard with tables. But I found that out at the beginning, when I sorted mine the table row and my record number matching screw up. Oh I was using the table setAutoRowSorter(true) thing.

At the end I didn't bother with sorting. And a column model is needed to not screw up the record number. It's your choice.



Hi,
There is the method in JTable that helps mapping the rows.
Greetings,
Liviu
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do sort the table.

Only problem is the rate field (I'm doing the URLyBird assignement) which has the curreny symbol included. Sorting on that column gives the lexical sorting and not the expected (numerical) sorting order. But I don't bother with this problem as I find that user expect the table to be sorted by clicking on the header. I can't think of an appripriate way to extract the currency information from the string field. Nowhere it is mentioned that the currencyl smybol is ISO 4217-compliant. So I stick with lexical sorting.

I only had to make sure that any selectred row stays selected after performing a search as the selected row might change and I have to find it again after the search operation and reselect it.
 
Liviu Carausu
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Axel Leucht wrote:I do sort the table.
So I stick with lexical sorting.



Hi,
I see here a problem: The column is not sorted as the user expects... (like : who's the cheapest contractor in the area ?).
With the recession it can help a lot
Greetings,
Liviu
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't do it. I'm doing the Bodgitt & Scarper assignment. There is no requirement for sorting the table, so I think you can only lose.
Cheers-
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Axel Leucht wrote:I do sort the table.

Only problem is the rate field (I'm doing the URLyBird assignement) which has the curreny symbol included. Sorting on that column gives the lexical sorting and not the expected (numerical) sorting order. But I don't bother with this problem as I find that user expect the table to be sorted by clicking on the header. I can't think of an appripriate way to extract the currency information from the string field. Nowhere it is mentioned that the currencyl smybol is ISO 4217-compliant. So I stick with lexical sorting.

I only had to make sure that any selectred row stays selected after performing a search as the selected row might change and I have to find it again after the search operation and reselect it.



You need to use a comparator for the record value object. Then what I did was substring whatever is after the currency symbol and cast it into a Double. Then use the compareTo(). This needs to be done for the rate field. The size field (if you have one also needs to have a comparator).
 
Axel Leucht
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Yucca Nel wrote:
You need to use a comparator for the record value object. Then what I did was substring whatever is after the currency symbol and cast it into a Double. Then use the compareTo(). This needs to be done for the rate field. The size field (if you have one also needs to have a comparator).


I know how to do it with a comparator.

Problem are with currencies more than one character long. For example the Denmark Kroner is abbreviated as 'kr', (two character) and the Switzerland Francis 'CHF' (three character).

But I will write a comparator for the size Attribute, which I forgot. I'll look into whether I can parse the currency with a regex-pattern.
 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Axel Leucht wrote:

Yucca Nel wrote:
You need to use a comparator for the record value object. Then what I did was substring whatever is after the currency symbol and cast it into a Double. Then use the compareTo(). This needs to be done for the rate field. The size field (if you have one also needs to have a comparator).


I know how to do it with a comparator.

Problem are with currencies more than one character long. For example the Denmark Kroner is abbreviated as 'kr', (two character) and the Switzerland Francis 'CHF' (three character).

But I will write a comparator for the size Attribute, which I forgot. I'll look into whether I can parse the currency with a regex-pattern.



Yes but when you create a new Double from the substring you get a nfe(if there's still a non numeric char in the substtring) and can cater for it.
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all;

I implemented the sortor for the table using the following code:



i don't know but I think this code will give us more control on the sorter than just .

please what you think guys ?

best regards.
Mohamed Sulibi
SCJP, SCJD in progress (from 1/8/2007 till now)
 
Axel Leucht
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do both:
 
reply
    Bookmark Topic Watch Topic
  • New Topic