问题
I am using jquery datatables plugin: https://www.datatables.net/download/index .. I have a table header that is generated using jquery. I added a checkbox to one of the columns of the table. Each time I click on that checkbox, I get the following error:
Uncaught TypeError: Cannot assign to read only property 'length' of false
I went to look in the code for jquery and here is what I see in my console:
For reference, the function causing an error is:
function _fnSortListener ( settings, colIdx, append, callback )
{
var col = settings.aoColumns[ colIdx ];
var sorting = settings.aaSorting;
var asSorting = col.asSorting;
var nextSortIdx;
var next = function ( a, overflow ) {
var idx = a._idx;
if ( idx === undefined ) {
idx = $.inArray( a[1], asSorting );
}
return idx+1 < asSorting.length ?
idx+1 :
overflow ?
null :
0;
};
// Convert to 2D array if needed
if ( typeof sorting[0] === 'number' ) {
sorting = settings.aaSorting = [ sorting ];
}
// If appending the sort then we are multi-column sorting
if ( append && settings.oFeatures.bSortMulti ) {
// Are we already doing some kind of sort on this column?
var sortIdx = $.inArray( colIdx, _pluck(sorting, '0') );
if ( sortIdx !== -1 ) {
// Yes, modify the sort
nextSortIdx = next( sorting[sortIdx], true );
if ( nextSortIdx === null && sorting.length === 1 ) {
nextSortIdx = 0; // can't remove sorting completely
}
if ( nextSortIdx === null ) {
sorting.splice( sortIdx, 1 );
}
else {
sorting[sortIdx][1] = asSorting[ nextSortIdx ];
sorting[sortIdx]._idx = nextSortIdx;
}
}
else {
// No sort on this column yet
sorting.push( [ colIdx, asSorting[0], 0 ] );
sorting[sorting.length-1]._idx = 0;
}
}
else if ( sorting.length && sorting[0][0] == colIdx ) {
// Single column - already sorting on this column, modify the sort
nextSortIdx = next( sorting[0] );
sorting.length = 1;
sorting[0][1] = asSorting[ nextSortIdx ];
sorting[0]._idx = nextSortIdx;
}
else {
// Single column - sort only on this column
sorting.length = 0;
sorting.push( [ colIdx, asSorting[0] ] );
sorting[0]._idx = 0;
}
// Run the sort by calling a full redraw
_fnReDraw( settings );
// callback used for async user interaction
if ( typeof callback == 'function' ) {
callback( settings );
}
}
My table header looks like this:
This is my table definition:
[<div id="fulfillment_board_wrapper" class="dataTables_wrapper no-footer show-batch-select"><div class="dataTables_scroll"><div class="dataTables_scrollHead" style="overflow: hidden; position: relative; border: 0px; width: 100%;">…</div><div class="dataTables_scrollBody" style="position: relative; overflow: auto; width: 100%; height: 550px;">…</div></div></div>
based on the suggestion below I used:
$('#fulfillment_board_wrapper').dataTable({"columnDefs": [{"orderable": false, targets:0}]})
inside my javascript file. However, i am still getting an error.
The checkbox to the left of VIP is causing the error.. How can I prevent this error from happening? How can I stop this listener from listening?
来源:https://stackoverflow.com/questions/33038281/jquery-datatables-is-giving-an-error-when-clicking-on-a-checkbox