Skip to content

Commit

Permalink
Fix: Columns which were marked as not orderable would still trigger a…
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanJard committed Feb 28, 2024
1 parent 6e30961 commit cc2970b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
24 changes: 16 additions & 8 deletions js/core/core.sort.js
Expand Up @@ -40,8 +40,14 @@ function _fnSortAttachListener(settings, node, selector, column, callback) {

// Allow the processing display to show
setTimeout( function () {
var run = false;

for ( var i=0, ien=columns.length ; i<ien ; i++ ) {
_fnSortAdd( settings, columns[i], i, e.shiftKey );
var ret = _fnSortAdd( settings, columns[i], i, e.shiftKey );

if (ret !== false) {
run = true;
}

// If the first entry is no sort, then subsequent
// sort columns are ignored
Expand All @@ -50,13 +56,15 @@ function _fnSortAttachListener(settings, node, selector, column, callback) {
}
}

_fnSort( settings );
_fnSortDisplay( settings );
_fnReDraw( settings, false, false );
_fnProcessingDisplay( settings, false );
if (run) {
_fnSort( settings );
_fnSortDisplay( settings );
_fnReDraw( settings, false, false );
_fnProcessingDisplay( settings, false );

if (callback) {
callback();
if (callback) {
callback();
}
}
}, 0);
}
Expand Down Expand Up @@ -362,7 +370,7 @@ function _fnSortAdd ( settings, colIdx, addIndex, shift )
};

if ( ! col.bSortable ) {
return;
return false;
}

// Convert to 2D array if needed
Expand Down
13 changes: 13 additions & 0 deletions test/options/columns/column_orderable.js
Expand Up @@ -117,5 +117,18 @@ describe('columns.orderable option', function() {
expect($('#example thead th').eq(3).hasClass('dt-ordering-asc')).toBe(true);
expect($('#example thead th').eq(3).hasClass('dt-orderable-none')).toBe(true);
});

it('Does not draw if order disables', async function() {
let table = $('#example').DataTable();
let drawn = false;

table.on('draw', function () {
drawn = true;
});

await dt.clickHeader(2);

expect(drawn).toBe(false);
});
});
});

0 comments on commit cc2970b

Please sign in to comment.