num-html does not work
num-html does not work
ashibahl007
Posts: 22Questions: 4Answers: 0
Hi Allan,
I have 5 datatables, but all datatables have same columns, different data. Here is a debug link :
http://debug.datatables.net/ohakof
I have num-html datatype and this doesnt seem to work : https://datatables.net/plug-ins/sorting/num-html
I need to sort these columns.
How do I achieve that ?
Regards,
Ashish
This discussion has been closed.
Answers
The "num-html" link you posted clearly states that num-html is deprecated and should be replaced by other functionality.
what functionality ?
Its built in to DataTables. DataTables should automatically detect columns with HTML and numbers in them and sort as required.
Could you link to a page showing the issue please?
Allan
i have created a fiddle
this might help you know the issue
https://jsfiddle.net/s7ftncch/
Is it the second column you are concerned about? You've used the sType option for the other two.
The "Share Location" column won't sort numerically since it contains non-numeric data (the string
Share Location
in the first row).Allan
it is just an example
data is the same as in debug tools link
I'll try to make some time next week to dig through it. If you could provide link to the page showing the issue that would make things easier and quicker.
Allan
Below is an updated link of what I wanna do :
https://jsfiddle.net/s7ftncch/2/
regards,
Ashish
And which column is it that is causing you issues?
Distance, Visits, Process, Places and usergroup columns
I'm getting a syntax error in the JSFiddle and nothing is running for me. Is your browser now showing a syntax error?
Allan
No errors as such, made sure though that I have included all the necessary files. Could you guide me where am I wrong ?
An updated Fiddle link :
https://jsfiddle.net/s7ftncch/4/
can you guide me why isn't sorting working on the mentioned columns?
Don't set the
columns.type
option unless you really understand the sorting plug-ins. DataTables will automatically detect the number types. For example you are setting thetype
for the Distance column to benatural
- but there is no natural sorting plug-in in your code - hence there is an error shown when you try to sort by that column.Removing the
type
option for those columns allows them to sort: https://jsfiddle.net/s7ftncch/5/ .Allan
https://jsfiddle.net/s7ftncch/6/
check this fiddle and try sorting visits column, it doesn't have any sType, still sorting happening in this order :
4200
2
10
0
whereas it should be
4200
10
2
0
and it has issue in sorting in ascending as well
NOTE : Where ever i have mentioned sTypes, I have included the respective file for it in my project, but not included it here in fiddle
You are using a very old version of DataTables (1.9.0).
1.10.13 is the current release and your example works well with the current release.
Allan
updating datatables also doesn't help me sort my data in my project still.
It worked in the example I linked to. Please link to a test case showing the issue (as I've requested before) if you are having problems with it.
Allan
I figured a solution to my problem.
It wasn't sorting the columns anyway after updating datatable version.
What I did was :
1. cleared my datatable using fnClearTable()
2. added data using fnAddData() and then finally
3. redraw datatables using fnDraw()
Hello,
I just ran into this issue, and here my 2c on observation.
It looks like the sorter is not working when data is loaded in via a pre-defined DOM table.
I suspect that the 'numeric' value in the cells are in fact read as string values, thus becomes unsortable.
If the same data is loaded via fnAddData(), and not cast from string to numeric, I can reproduce the same failure.
If the data is cast, then it works like a charm.
Since I must load the data from a predefined DOM table (reasons not within scope of this comment) I solved the issue by using two columns, one hidden, and set as the data sort src, the visible one contains the 'numeric' value and its html display.
Example:
which holds (example data):
with column definitions as
and sorting works 100%
I would like to withdraw my previous comment. In fact, it doe snot work. Data is still sorted as strings, unless loaded via a dataset
That won't sort numerically since it contains non-numeric data (the
"
).I would suggest that you use orthogonal data for this sort of data.
Allan