Bug: The colReorder.move(pos_1, pos_2) does not update the data-column-index for each of the 'th'

Bug: The colReorder.move(pos_1, pos_2) does not update the data-column-index for each of the 'th'

bhaulikbhaulik Posts: 10Questions: 3Answers: 0

The colReorder.move() does not update the data-column-index accordingly - when the value tags are inspected after the move method is called, i.e visually the columns change positions however this is inconsistent with the data-column-index values under inspection. Thus causing further issues when working with the positioning in any other way.
Try testing this by initializing a basic DataTable with colReorder and somewhere in the js call the move method to relocate a column. Then inspect and observe the values of the data-column-index. Additionally, try dragging and observe the change of the data-column-index values. To make things more interesting try using the Column Visibility option to see the inconsistency of the positions when certain columns are removed from the visibility.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    Answer ✓

    Thanks for posting this. I've added it as an issue for ColReorder so I don't forget to fix it before the next release.

    Allan

  • bhaulikbhaulik Posts: 10Questions: 3Answers: 0

    Thank you for the response Allan

  • peterdrinnanpeterdrinnan Posts: 4Questions: 0Answers: 0

    I have been trying to work around this issue using colReorder.transpose() but it is messy. Is it likely there may be a fix for this issue in early 2018?

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin

    I'll post back here whenever I get a chance to fix it. I can't say for sure when, as I've got a fair old back log at the moment, but I will try to get it done as soon as I can.

    Allan

  • peterdrinnanpeterdrinnan Posts: 4Questions: 0Answers: 0

    Thanks for the update Allan.

  • peterdrinnanpeterdrinnan Posts: 4Questions: 0Answers: 0

    What fixed this for me for colReorder version 1.4.1 was to add $.fn.dataTable.Api( this.s.dt ).rows().invalidate(); in the colReorder 'fnOrder' method. See code sample below:

        "fnOrder": function ( set, original )
        {
            var a = [], i, ien, j, jen;
            var columns = this.s.dt.aoColumns;
    
            if ( set === undefined ){
                for ( i=0, ien=columns.length ; i<ien ; i++ ) {
                    a.push( columns[i]._ColReorder_iOrigCol );
                }
    
                // peter drinnan - fix for sorting index
                $.fn.dataTable.Api( this.s.dt ).rows().invalidate();
    
                return a;
            }
    
            // The order given is based on the original indexes, rather than the
            // existing ones, so we need to translate from the original to current
            // before then doing the order
            if ( original ) {
                var order = this.fnOrder();
    
                for ( i=0, ien=set.length ; i<ien ; i++ ) {
                    a.push( $.inArray( set[i], order ) );
                }
    
                set = a;
            }
    
            this._fnOrderColumns( fnInvertKeyValues( set ) );
    
            return this;
        },
    
This discussion has been closed.