该bSort
参数在默认情况下设置为“true”
var ColumnFilterWidget = function( $Container, oDataTableSettings, i, widgets ) {
...
}
您的设置"bsort": false
未评估,因此被忽略。要使其被应用,您需要修改上述功能并添加:
if ( 'bSort' in oDataTableSettings.oInit.oColumnFilterWidgets ) {
widget.bSort = oDataTableSettings.oInit.oColumnFilterWidgets.bSort;
}
紧接着
if ( 'oColumnFilterWidgets' in oDataTableSettings.oInit ) {
最终函数将如下所示:
var ColumnFilterWidget = function( $Container, oDataTableSettings, i, widgets ) {
var widget = this, sTargetList;
widget.iColumn = i;
widget.oColumn = oDataTableSettings.aoColumns[i];
widget.$Container = $Container;
widget.oDataTable = oDataTableSettings.oInstance;
widget.asFilters = [];
widget.sSeparator = '';
widget.bSort = true;
widget.iMaxSelections = -1;
if ( 'oColumnFilterWidgets' in oDataTableSettings.oInit ) {
if ( 'bSort' in oDataTableSettings.oInit.oColumnFilterWidgets ) {
widget.bSort = oDataTableSettings.oInit.oColumnFilterWidgets.bSort;
}
if ( 'sSeparator' in oDataTableSettings.oInit.oColumnFilterWidgets ) {
widget.sSeparator = oDataTableSettings.oInit.oColumnFilterWidgets.sSeparator;
}
if ( 'iMaxSelections' in oDataTableSettings.oInit.oColumnFilterWidgets ) {
widget.iMaxSelections = oDataTableSettings.oInit.oColumnFilterWidgets.iMaxSelections;
}
if ( 'aoColumnDefs' in oDataTableSettings.oInit.oColumnFilterWidgets ) {
$.each( oDataTableSettings.oInit.oColumnFilterWidgets.aoColumnDefs, function( iIndex, oColumnDef ) {
var sTargetList = '|' + oColumnDef.aiTargets.join( '|' ) + '|';
if ( sTargetList.indexOf( '|' + i + '|' ) >= 0 ) {
$.each( oColumnDef, function( sDef, oDef ) {
widget[sDef] = oDef;
} );
}
} );
}
}
widget.$Select = $( '<select></select>' ).change( function() {
var sSelected = widget.$Select.val(), sText, $TermLink, $SelectedOption;
if ( '' === sSelected ) {
// The blank option is a default, not a filter, and is re-selected after filtering
return;
}
sText = $( '<div>' + sSelected + '</div>' ).text();
$TermLink = $( '<a class="filter-term" href="#"></a>' )
.addClass( 'filter-term-' + sText.toLowerCase().replace( /\W/g, '' ) )
.text( sText )
.click( function() {
// Remove from current filters array
widget.asFilters = $.grep( widget.asFilters, function( sFilter ) {
return sFilter != sSelected;
} );
$TermLink.remove();
if ( widgets.$TermContainer && 0 === widgets.$TermContainer.find( '.filter-term' ).length ) {
widgets.$TermContainer.hide();
}
// Add it back to the select
widget.$Select.append( $( '<option></option>' ).attr( 'value', sSelected ).text( sText ) );
if ( widget.iMaxSelections > 0 && widget.iMaxSelections > widget.asFilters.length ) {
widget.$Select.attr( 'disabled', false );
}
widget.fnFilter();
return false;
} );
widget.asFilters.push( sSelected );
if ( widgets.$TermContainer ) {
widgets.$TermContainer.show();
widgets.$TermContainer.prepend( $TermLink );
} else {
widget.$Select.after( $TermLink );
}
$SelectedOption = widget.$Select.children( 'option:selected' );
widget.$Select.val( '' );
$SelectedOption.remove();
if ( widget.iMaxSelections > 0 && widget.iMaxSelections <= widget.asFilters.length ) {
widget.$Select.attr( 'disabled', true );
}
widget.fnFilter();
} );
widget.$Container.append( widget.$Select );
widget.fnDraw();
};