Sorting columns by Numeric Value containing HTML and Text

Sorting columns by Numeric Value containing HTML and Text

KyleRKyleR Posts: 1Questions: 1Answers: 0
edited August 2014 in Free community support

I have tables with data in such as:

<td><span class="label label-primary">$9.77 PKA</span></td> <td><span class="label label-primary">$11.14 PKA</span></td>

The sorting of the columns, is ordering it by the HTML or TEXT, as $9.77 is less than $11.14 but appears first when ordered.

How can I go about achieving this?

Here is my current JS:

$("#zero-configuration").dataTable({
    'iDisplayLength': 200
});

Answers

  • allanallan Posts: 63,512Questions: 1Answers: 10,472 Site admin

    As there is non-numeric data (the PKA part) DataTables can't automatically detect this is a numeric data type - hence why it is string sorting.

    So there are a number of options to address this:

    1. Use orthogonal data - in particular checkout the HTML5 part if you are using a DOM sourced table
    2. Use the natural sort plug-in
    3. Create your own plug-in that will handle this data type

    Allan

This discussion has been closed.