Row index in a custom sort function

Row index in a custom sort function

gSibingergSibinger Posts: 10Questions: 4Answers: 0

For a custom sort I need to access parts of the sorted row data other than the compared values. So I would want to access the row data by table.row( index ).data();
However, I would need a row index for that and the function only provides the values to compare.

This is the code:

jQuery.extend(jQuery.fn.dataTableExt.oSort, {    

    'grouped-asc': function(a, b) {
        var thisData = tabletool.table.row(idx).data();
        // ...
        return a < b ? -1 : a > b ? 1 : 0;
    },

    'grouped-desc': function(a, b) {
        var thisData = tabletool.table.row(idx).data();
        // ...
        return a < b ? 1 : a > b ? -1 : 0;
    }
});

How can I include the row index in this?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    Hi @gSibinger ,

    That's not possible with the sorting extensions. As you say, you're only comparing single values and there's no way of mapping that back onto the original row.

    There are two other options that may be relevant. First, you can use columns.orderData to use values of another column when ordering. Also, orthogonal data can be used to change the value of the data used for sorting, see columns.render. This would have the information for the entire row so can be considered.

    Cheers,

    Coln

  • gSibingergSibinger Posts: 10Questions: 4Answers: 0

    Hi Colin,

    I was able to use columns.render to send an object containing all necessary information to the sort function. Thanks for your help!

    Regards

    Georg

This discussion has been closed.