How do I exclude the span tag from being sorted in a table cell?

How do I exclude the span tag from being sorted in a table cell?

SamerSamer Posts: 2Questions: 1Answers: 0
edited May 2014 in Free community support

In my tables I have my data in each cell like this:

<td>
DATA THAT NEEDS TO BE SORTED
<span>Data Label</span>
</td>

How do I stop it from including the span tag in the sorting?

Thanks!

Answers

  • JamaurJamaur Posts: 87Questions: 10Answers: 0
    edited June 2014

    In Datatables 1.9, I used aoColumnDefs.mData.

    function (source, type, val) {
        if (type === 'set') {
            source[iColIndex] = val;
            return;
        }
        else if (type === 'sort') {
            // source[iColIndex] = is the cell value (<td> DATA THAT NEEDS TO BE SORTED <span>Data Label</span> </td>)
            // return the right data to sort
        }
        return source[iColIndex];
    }
    

    In Datatables 1.10 equivalent is columns.data.

  • SamerSamer Posts: 2Questions: 1Answers: 0

    I don't really understand how I'm meant to use that function.

    The only code I have at the moment is the initialization code:
    var playersTable = $('#players-table').DataTable();

    What would I need to do from here?

  • JamaurJamaur Posts: 87Questions: 10Answers: 0

    In datatables 1.9, I would do something like this:

    $('#players-table').dataTable({
        aoColumnDefs: [{
            mData: function (source, type, val) {
                if (type === 'set') {
                    source[iColIndex] = val;
                    return;
                }
                else if (type === 'sort') {
                    // source[iColIndex] = is the cell value (<td> DATA THAT NEEDS TO BE SORTED <span>Data Label</span> </td>)
                    // return the right data to sort
                }
                return source[iColIndex];
            }, aTargets: [iColIndex]
        }]
    });
    

    iColIndex is the column index

This discussion has been closed.