Sortable Table needs to Sort by considering "_"

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Sortable Table needs to Sort by considering "_"

Postby vanitha » Tue Feb 04, 2014 5:39 am

Sortable Table is now not sorting the the columns correctly if we have "_" in the column content for example. Because "_" is almost used by many people to display column values to neatly describe them

I have following in the colums
SELL
BUY_MINUS
APPLE
BUY

if we sort the column at present the content is coming as

APPLE
BUY
SELL
BUY_MINUS

BUT I think it should consider "_" also and the content needs to be sorted like

APPLE
BUY
BUY_MINUS
SELL
vanitha
 
Posts: 8
Joined: Thu May 03, 2012 2:04 am

Re: Sortable Table needs to Sort by considering "_"

Postby JIDE Support » Tue Feb 04, 2014 9:01 am

I don't think it makes any sense that we put SELL before BUY_MINUS because the first letter 'S' is clearly after 'B', regardless '_'. I felt there are something else going on in your code. Could you please send us a test case so that we can compile and run to see the issue?
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Sortable Table needs to Sort by considering "_"

Postby vanitha » Wed Feb 05, 2014 10:22 pm

Thanks for your reply, sorry for not giving a brief of my requirement in previous mail i want a improvement in sortable table that if we add any renderer to the table content also it should get sorted. Ex: actual mu table content is 1,2,3,4 but I added a renderer to that column so that they will display as "BUY,SELL,BUY_MINUS,SELL_MINUS" respectively. in this case if we sort its sorting the content and giving the result as 1,2,3,4(which may be correctbut looking wrong on the screen as "BUY,SELL,BUY_MINUS,SELL_MINUS" .

As it was common that user can add renderers to there table contents, we in our Project use every where the Sortable table but now its becoming the issue for us as if renderer added sorting is not happening can you please suggest us on this

I am attaching the sample program which will replicate this issue

Thanks
Vanitha
Attachments
SortableDemo.java
Main class
(1.84 KiB) Downloaded 1953 times
SortableTableModel.java
Table model class
(1.07 KiB) Downloaded 1866 times
vanitha
 
Posts: 8
Joined: Thu May 03, 2012 2:04 am

Re: Sortable Table needs to Sort by considering "_"

Postby JIDE Support » Wed Feb 05, 2014 11:18 pm

There are other ways to do it but I'll suggest doing it using the JIDE approach. The logic behind this approach is you never want to touch the cell renderer when sorting. The cell renderer is a UI component. It is slow.

Step 1: get rid of your CustomTableCellRenderer. Never use a cell renderer if it can be done using an ObjectConverter because it is just a simple string conversion. Instead of using cell renderer, create an ObjectConverter and register it on ObjectConverterManager using int.class with a ConverterContext("whatever_name_you_want"). In your table model, implement ContextSensitiveTableModel and return int.class in getColumnClassAt and ConverterContext("whatever_name_you_want") in getConverterContexAt.

After step 1, you will be able to see the integers are displayed as "BUY" etc. without using a cell renderer. If not, please refer to the developer guide and examples to get it working.

Step 2: Write a special Comparator<Integer> which uses the ObjectConverter you created in step 1 and convert the int values to String first, then compare. Register the Comparator to ObjectComparatorManager using int.class and new ComparatorContext("whatever_name_you_want").

Step 3: Use the Comparator you created in step 2. You need to create a SortableTableModel (the JIDE's SortableTableModel, not the SortableTableModel you created. You should consider rename your SortableTableModel to something else. Otherwise it will be confusing). Using

Code: Select all
SortableTableModel model = new SortableTableModel(yourModel);
model.setColumnComparatorContextProvider(...); // make sure you return ComparatorContext("whatever_name_you_want") for that column.
SortableTable table = new SortableTable(model);
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Sortable Table needs to Sort by considering "_"

Postby vanitha » Fri Feb 14, 2014 3:28 am

Thanks For ur Solution.. it Worked
vanitha
 
Posts: 8
Joined: Thu May 03, 2012 2:04 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 15 guests