How to access a second column in an external sort plugin

How to access a second column in an external sort plugin

rotorboyrotorboy Posts: 18Questions: 4Answers: 0

I currently have an external sort plugin to sort a single column based on a conditional in the pre-amble:

jQuery.extend( jQuery.fn.dataTableExt.oSort,{
"enum-pre": function ( column_1 ) {

                        switch( column_1 ) {
                            case "A":        return 1;
                            case "B":        return 2;
                            case "C":        return 3;

                            default:            return 4;

I now need to include data from another column into that conditional:

"enum-pre": function ( column_1, column_2 ) {

        if (column_1 = 'A' and column_2 = 'X') return 1;
                if (column_1 = 'B' and column_2 = 'Y') return 2;

Is there an "approved" way to go about accessing the second column?

Thanks

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 64,076Questions: 1Answers: 10,566 Site admin
    edited June 2020 Answer ✓

    No - I'm afraid you can't. The sorting plug-ins are given the data for the target column only and have no access to the data in the other columns.

    If you want to sort a column over two columns of data you either need to:

    1. Include all of the data in the first column, or
    2. Use columns.orderData to sort over multiple columns (note that they are still sorted by data independently - the second column's data will only be used if the first one has the same data in two rows - think multi-column sorting).

    Allan

  • rotorboyrotorboy Posts: 18Questions: 4Answers: 0

    Allan;

    As always, thanks for getting back to me so quickly. Disappointing to hear, but I understand.

    Already using orderData, but as you point out, it is limited as a "secondary", and I need it to be interwoven in the pre-amble of first. I will try to be creative.

    Thanks again.

This discussion has been closed.