colReorder fnOrder doesn't recalculate data-column-index properly

colReorder fnOrder doesn't recalculate data-column-index properly

dykstraddykstrad Posts: 20Questions: 0Answers: 1

Hey Allan,

I have noticed that there is a difference between reordering the columns using the mouse and calling fnOrder manually.

The problem is that when you call fnOrder manually it updates the data-column-index attribute but that doesn't update the jQuery data model.

"_fnSetColumnIndexes": function ()
    {
        $.each( this.s.dt.aoColumns, function (i, column) {
            $(column.nTh).attr('data-column-index', i);
        } );
    }

notice the attr call in _fnSetColumnIndexes. All you need to do is add a jQuery data call to the mix and it updates it properly.

"_fnSetColumnIndexes": function ()
    {
        $.each( this.s.dt.aoColumns, function (i, column) {
            $(column.nTh).attr('data-column-index', i);
            $(column.nTh).data('column-index', i);
        } );
    }

Hope this helps.

David

Replies

  • dykstraddykstrad Posts: 20Questions: 0Answers: 1
    edited June 2014

    This is because according to the jQuery documentation.

    The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).

This discussion has been closed.