Have a dataTable and have trouble sorting numbers
Have a dataTable and have trouble sorting numbers
ashibahl007
Posts: 22Questions: 4Answers: 0
I am using the latest revision of datatables and i am facing a trouble sorting numbers.
For instance,
I have numbers
0
100
2
3
1
They get sorted as
0
1
100
2
3
100 must be the last one in the column !
Here is a datatable debugger link:
http://debug.datatables.net/eyocil
any help would be greatful
Regards,
Ashish
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can define the column type.
See https://datatables.net/reference/option/columns.type
Which column is it in your table specifically that is causing the issue? That you are seeing will occur if you mix string content and numbers - there must be a string value in that column somewhere.
You shouldn't need to specify a
columns.type
option - it should happen automatically based on the data in the column.Allan
Problem occurs in column 5 - Battery..
I have mentioned % in my jquery code..
Do you think this is causing it ?
That actually solved my query.. I removed the symbol from the code and now it works perfectly fine.. But if i have to use % sign in my jquery, (which is required) how can I achieve that ?
Ashish
I don't really understand. You are using
%
as a selector, or something else?I have a column named battery and the values are returned via db..
so, in my jquery, i have put data.battery+ '%'+ that includes % symbol in front of the values..
I'd really need a link to the page showing the issue to understand why it isn't working.
Allan
What I meant was that my datatable had a column named battery in which the values are returned from database.. Using jQuery, I had put a % symbol just in front of the numeric data to indicate battery percentage.. So I had to sort them because sorting was happening as mentioned above.
I just needed numeric sorting with % sign with something like this
'''{sType : num,percent}'''
This link helped me out
https://datatables.net/forums/discussion/16385/sorting-with-signed-numbers-and-percentage-signs
Ashish
Thanks for the update, good to hear you have it working.
Allan