Table column sort - Numeric values

Hello,
I have a table that shows a lot of columns and the option sort it’s true for all of them and it’s working when the value is a string, like name
(i.e:
John
Charles
Apu
when i click in asc sort:
Apu
Charles
John
)

But when i’m trying to do this with numeric values, it’s not working correctly.
(i.e:
1234
254
15
3454.45
25178

when i click in asc sort
1234
15
25178
254
3454.45

when the correctly order should be
15
254
1234
25178
3454.45
)

I’ve tried to change for numeric in converter properties, double, but it’s not working.
Can someone help me?

Thanks!

Try changing the expression used for the “Sort” property in the columns that contain numeric data to convert the value to a number before it is used for sorting.

For example, if your “Sort” value of a column is something like this:

#{row.field1}

Then you can use the provided caf:xn function to wrap the original expression and convert that value to a number like this:

#{caf:xn(row.field1)}
1 Like

Thank you Eric!! It’s working now!

Eric,

Do you know in which document I can find more information about this functionality?

Thanks!

What specific functionality are you referring to?

If you are talking about the caf:xn function, then the CAF Tag Library Reference documentation is where the CAF functions that can be used in an EL expression are described.

Thank you Eric,

Last question, is this documentation available only on 9.6? (CAF Tag Library Reference)
I’d like to do the same for date values.

Thanks!

Yes, 9.6 was the first release that contained the CAF Tag Library Reference documentation.

The provided CAF functions don’t currently have a method for date values.

I haven’t tried this, but you should be able to create your own custom function in your page bean that does your conversion logic. This ability to invoke methods with parameters is provided by the EL 2.2 standard.

For example, add a new method to the your page bean:

public long dateToLong(String value) {
   long ms = 0;
   //TODO: convert the date string to a number here..
   return ms;
}

And then you can change the sort expression to call your custom function:

#{activePageBean.dateToLong(row.field1)}  
1 Like

Thanks again, Eric!