aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes B&S using a sorted column table to display the records? How many of you have done this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "B&S using a sorted column table to display the records? How many of you have done this?" Watch "B&S using a sorted column table to display the records? How many of you have done this?" New topic
Author

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

Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

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?


SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

Hum... I guess not, since it isn't really a requirement, you know... I myself didn't do it


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Liviu Carausu
Ranch Hand

Joined: Oct 07, 2004
Posts: 158
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


Oracle Certified Master Java SE6 Developer(SCJD),
OCE JEE 6 JSP and Servlets Developer.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2409
    
    7

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2265
    
    3

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

Joined: Oct 07, 2004
Posts: 158
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
Axel Leucht
Greenhorn

Joined: Jan 19, 2009
Posts: 21
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.


Regards

SCJP, SCJD
Liviu Carausu
Ranch Hand

Joined: Oct 07, 2004
Posts: 158
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
Paul Balm
Ranch Hand

Joined: Dec 13, 2008
Posts: 63
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-


SCJP 1.4 -- SCJD Java 2 -- OCM JEA 5
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

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

Joined: Jan 19, 2009
Posts: 21
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

Joined: Nov 20, 2008
Posts: 147

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.
mohamed sulibi
Ranch Hand

Joined: Sep 04, 2005
Posts: 169
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

Joined: Jan 19, 2009
Posts: 21
I do both:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: B&S using a sorted column table to display the records? How many of you have done this?