Numeric sorting
Numeric sorting
scsbreese
Posts: 8Questions: 2Answers: 0
I have a table with numbers ranging from 0 to 10,000 and the numeric sorting is failing. Sorting in descending order results in:
980, 9600, 960, 93, 890.. etc.
1.10 claims to have smart sorting based on number type but I am not experiencing this feature.
Any help would be nice.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Works fine for me (see Age column). Maybe post a test case where it's not working (as described here)?
In further investigation, this is seems to be based on JQuery Mobile, it is prepending the data with some html code and text.
Visible data: 1,000
HTML data:
<b class="ui-table-cell-label">Amount Needed - Scheduled</b>
"1,000"
To answer this question (and hopefully for any Google searches):
Adding the data-role="table" to the <table tag causes the table-cell-label to be added.
If you remove data-role="table" then the columns will render naturally and numeric sorting will work.
This applies to DataTables and jQueryMobile.
Explicitly declare your column's type to be
numeric
as shown here: http://datatables.net/reference/option/columns.typeIf you don't define the column's type then dataTables will try to guess it. It looks like your data set contains also some non-numeric values so the guessing fails