DataTables comma on numbers
DataTables comma on numbers
Hello. I have a dataTable in a jsp page wherein I get data from the database. My problem is getting commas in the dataTables itself rather than have 00000000 continuously, it would be much better if it is 000,000,000. I have done this by using DecimalFormat in java. So now, I have commas on my number inputs in the dataTable.
The problem is they don't sort accordingly. For example I have
2,504
203,
1,251
When I sort, the 203 still remains in the middle rather than going in ascending or descending order. Please help thank you!
My table goes like this:
Columns: Location, Age Group, Both Count, Male Count, Female Count (of which the counts are the numbers with commas if reaching the thousands)
This question has an accepted answers - jump to answer
Answers
If you continue to return just a plain, unformatted number, you will then be able to use DataTables' built in number renderer.
Allan
I didn't know there was such a thing. Thank you so much! If it's not too much of a bother, would it be alright to ask where to put the code for the number renderer?
If my code is like this;
The documentation I linked to above gives an extensive overview of how to use the renderers and how to implement them in code. See also the
columns.render
reference documentation.I'm not sure how well they will work with the
columns.orderDataType
option. Do you haveinput
elements in your table? If so, they aren't going to work well with renderer.Allan