RegisterSearchFAQ UsergroupsLog in
How to implement numeric renderer in table header filter

 
Reply to topic    Citra Technologies Forum Index » Report a Bug View previous topic
View next topic

How to implement numeric renderer in table header filter
Author Message
sreedevi



Joined: 11 Dec 2013
Posts: 3

Post How to implement numeric renderer in table header filter Reply with quote
Hi all,

I implemented numeric renderer in amount column and amount are formatted with 2 digits, but when i click the filter of amount column, it list out a long value after the decimal point.

Kindly advice me on above issue.



Scientigrid - Table header filter.JPG
 Description:
Screenshot attached
 Filesize:  34.3 KB
 Viewed:  228 Time(s)

Scientigrid - Table header filter.JPG


Wed Dec 11, 2013 3:53 am View user's profile Send private message Send e-mail
sreedevi



Joined: 11 Dec 2013
Posts: 3

Post Reply with quote
Hi all,

I need Filter table header value should be formatted with 2 digits. Kindly suggest me.
Wed Dec 11, 2013 11:40 pm View user's profile Send private message Send e-mail
support



Joined: 21 Feb 2006
Posts: 1463

Post Reply with quote
Hello my old friend!

You should use a custom PopupRenderer, just like in the demo:

Code:

//create the renderer
ListCellRenderer floatPopupRenderer = new PopupRenderer() {
   public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      if (value instanceof Float) {
         value = twoDigitNumberFormat.format(((Float) value).floatValue());
      }
      Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      return c;
   }
};

//install the renderer on the combo box
popupFilterHeaderModel.getComboBox().setRenderer(floatPopupRenderer);


In the above example, I am supposing that the values are Floats.

Thanks!
Fri Dec 13, 2013 4:21 am View user's profile Send private message
sreedevi



Joined: 11 Dec 2013
Posts: 3

Post Reply with quote
Hi,

Thank you. Now its working fine.

But one more issue, while filtering the particular amount column, inside the cell having the following amount values in each row
1.5991008
1.59894
1.599444
1.599477
1.601208

Renderer is set for both table and filter, so the amount are showing like this 1.60 in table and filter, while filtering it is not considering the five rows, it consider only one row for each amount filter. But i need to show all five rows while filtering 1.60.

Below coding is used for table renderer
TableCellRenderer nr = nonManifestTable.getDefaultRenderer(Number.class);
if ((nr instanceof NumberRenderer)) {
((NumberRenderer) nr).setNumberFormat(dispAmt);
((NumberRenderer) nr).setSpacing(false);
}
nonManifestTable.getColumnModel().getColumn(i).setCellRenderer(nr);

Kindly find the attachment and suggest me.
Thanks



Scientigrid - Table header filter1.JPG
 Description:
 Filesize:  29.78 KB
 Viewed:  197 Time(s)

Scientigrid - Table header filter1.JPG


Fri Dec 13, 2013 6:15 am View user's profile Send private message Send e-mail
support



Joined: 21 Feb 2006
Posts: 1463

Post Reply with quote
Hi,

This is a bit tricky, you should first make sure that there are no duplicate rounded values in the filter list, and then create and install your own custom filter.

For example:

First create the custom filter that compares rounded float values:

Code:
public class CustomFloatFilter extends FloatFilter {
   NumberFormat twoDigitNumberFormat;
   public CustomFloatFilter() {
      twoDigitNumberFormat = NumberFormat.getInstance();
      twoDigitNumberFormat.setMaximumFractionDigits(2);
      twoDigitNumberFormat.setMinimumFractionDigits(2);
   }
   public boolean accept(float i) {
      if (comparison == EQ) {
         String str1 = twoDigitNumberFormat.format(i);
         String str2 = twoDigitNumberFormat.format(value);
         Float newValue1 = Float.valueOf(str1);
         Float newValue2 = Float.valueOf(str2);
         return newValue1.equals(newValue2);
      }
      else {
         return super.accept(i);
      }
   }
}


Then create a PopupFilterHeaderModel subclass that takes care of the duplicate rounded float values:

Code:
PopupFilterHeaderModel fhm = new CustomPopupFilterHeaderModel() {
   public Collection getFilterValuesFromModel(int modelIndex, Collection list, int mode) {
      Collection c = super.getFilterValuesFromModel(modelIndex, list, mode);
      TreeSet s = new TreeSet();
      for (Iterator it = c.iterator(); it.hasNext();) {
         Float f = (Float) it.next();
         String str = twoDigitNumberFormat.format(f);
         Float newValue = Float.valueOf(str);
         s.add(newValue);
      }
      return s;
   }
};


Finally install the new custom filter for float values:

Code:
fhm.setDefaultFilter(Float.class, new CustomFloatFilter());

Sat Dec 14, 2013 8:14 am View user's profile Send private message
Display posts from previous:    

Reply to topic    Citra Technologies Forum Index » Report a Bug All times are GMT - 5 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group