Negative value sorting in text

Negative value sorting in text

YnjxsjmhYnjxsjmh Posts: 3Questions: 2Answers: 0

I want to sort some numbers in text: http://live.datatables.net/viruqawe/2/edit

As is shown in the test case, the number and text are seperated with _ sign. I tried to use natural.js, but it seems that it doesn't recogonize negative value which has a negative sign ahead.

I have viewed the plugins in https://datatables.net/plug-ins/sorting/, but I think all seem not help. I also tried to write my own:

jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "state-compare-pre": function ( a ) {
        return parseFloat($(a).text().split("_")[1]);
    },

    "state-compare-asc": function ( a, b ) {
        return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    },

    "state-compare-desc": function ( a, b ) {
        return ((a < b) ? 1 : ((a > b) ? -1 : 0));
    }
} );

However, my script doesn't work.

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.