num-html does not work

num-html does not work

ashibahl007ashibahl007 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

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    The "num-html" link you posted clearly states that num-html is deprecated and should be replaced by other functionality.

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0

    what functionality ?

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    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

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0

    i have created a fiddle

    this might help you know the issue

    https://jsfiddle.net/s7ftncch/

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    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

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0

    it is just an example

    data is the same as in debug tools link

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    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

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0

    Below is an updated link of what I wanna do :

    https://jsfiddle.net/s7ftncch/2/

    regards,
    Ashish

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    And which column is it that is causing you issues?

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0

    Distance, Visits, Process, Places and usergroup columns

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    I'm getting a syntax error in the JSFiddle and nothing is running for me. Is your browser now showing a syntax error?

    Allan

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0

    No errors as such, made sure though that I have included all the necessary files. Could you guide me where am I wrong ?

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0
    edited February 2017

    An updated Fiddle link :

    https://jsfiddle.net/s7ftncch/4/

    can you guide me why isn't sorting working on the mentioned columns?

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    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 the type for the Distance column to be natural - 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

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0
    edited February 2017

    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

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    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

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0

    updating datatables also doesn't help me sort my data in my project still.

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    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

  • ashibahl007ashibahl007 Posts: 22Questions: 4Answers: 0
    edited February 2017

    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()

  • ProxiBlueProxiBlue Posts: 2Questions: 0Answers: 0
    edited March 2018

    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:

    <th class="diameter-column hidepriority4">Diameter</th>
    <th class="diameter-column-sorter hide-column">Diameter Sorter</th>
    

    which holds (example data):

    <td class="hidepriority4 sorting_1">96<span class="sign">"</span></td>
    <td class="hidepriority4">96</td>
    

    with column definitions as

    { targets: "diameter-column",searchable: false, sortable: true, "dataSrc": "diameter-column-sorter"  },
    { targets: "diameter-column-sorter", 'visible': false, sortable: true, searchable: false, type: "num" },
    

    and sorting works 100%

  • ProxiBlueProxiBlue Posts: 2Questions: 0Answers: 0

    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

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin

    96<span class="sign">"</span>

    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

This discussion has been closed.