Impovement to variables used

pull/514/head
Przemysław Kłys 4 years ago committed by GitHub
parent 4cc9d34158
commit a1b1d7fec0

@ -49,12 +49,20 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) {
return true; return true;
} }
if ($.fn.dataTable.AlphabetSearch.caseSensitive) { if (context.oInit.alphabet !== undefined) {
if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0) === context.alphabetSearch ) { var columnId = (context.oInit.alphabet.column !== undefined) ? context.oInit.alphabet.column : 0
var caseSensitive = (context.oInit.alphabet.caseSensitive !== undefined) ? context.oInit.alphabet.caseSensitive : false
} else {
var columnId = 0
var caseSensitive = false
}
if (caseSensitive) {
if ( searchData[columnId].charAt(0) === context.alphabetSearch ) {
return true; return true;
} }
} else { } else {
if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0).toUpperCase() === context.alphabetSearch ) { if ( searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch ) {
return true; return true;
} }
} }
@ -64,11 +72,11 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) {
// Private support methods // Private support methods
function bin ( data ) { function bin ( data, options ) {
var letter, bins = {}; var letter, bins = {};
for ( var i=0, ien=data.length ; i<ien ; i++ ) { for ( var i=0, ien=data.length ; i<ien ; i++ ) {
if ($.fn.dataTable.AlphabetSearch.caseSensitive) { if (options.caseSensitive) {
letter = data[i] letter = data[i]
.toString() .toString()
.replace(/<.*?>/g, '') .replace(/<.*?>/g, '')
@ -90,13 +98,13 @@ function bin ( data ) {
return bins; return bins;
} }
function draw ( table, alphabet ) function draw ( table, alphabet, options )
{ {
alphabet.empty(); alphabet.empty();
alphabet.append( 'Search: ' ); alphabet.append( 'Search: ' );
var columnData = table.column($.fn.dataTable.AlphabetSearch.column).data(); var columnData = table.column(options.column).data();
var bins = bin( columnData ); var bins = bin( columnData, options );
$('<span class="clear active"/>') $('<span class="clear active"/>')
.data( 'letter', '' ) .data( 'letter', '' )
@ -104,7 +112,7 @@ function draw ( table, alphabet )
.html( 'None' ) .html( 'None' )
.appendTo( alphabet ); .appendTo( alphabet );
if ($.fn.dataTable.AlphabetSearch.addNumbers) { if (options.numbers) {
for (var i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
var letter = String.fromCharCode(48 + i); var letter = String.fromCharCode(48 + i);
@ -126,7 +134,7 @@ function draw ( table, alphabet )
.html( letter ) .html( letter )
.appendTo( alphabet ); .appendTo( alphabet );
} }
if ($.fn.dataTable.AlphabetSearch.caseSensitive === true) { if (options.caseSensitive) {
for (var i = 0; i < 26; i++) { for (var i = 0; i < 26; i++) {
var letter = String.fromCharCode(97 + i); var letter = String.fromCharCode(97 + i);
@ -153,11 +161,7 @@ $.fn.dataTable.AlphabetSearch = function ( context ) {
numbers: false numbers: false
}, table.init().alphabet); }, table.init().alphabet);
$.fn.dataTable.AlphabetSearch.column = options.column; draw( table, alphabet, options );
$.fn.dataTable.AlphabetSearch.caseSensitive = options.caseSensitive;
$.fn.dataTable.AlphabetSearch.addNumbers = options.numbers;
draw( table, alphabet );
// Trigger a search // Trigger a search
alphabet.on( 'click', 'span', function () { alphabet.on( 'click', 'span', function () {
@ -193,8 +197,6 @@ $.fn.dataTable.AlphabetSearch = function ( context ) {
}; };
}; };
$.fn.DataTable.AlphabetSearch = $.fn.dataTable.AlphabetSearch;
// Register a search plug-in // Register a search plug-in
$.fn.dataTable.ext.feature.push( { $.fn.dataTable.ext.feature.push( {
fnInit: function ( settings ) { fnInit: function ( settings ) {

Loading…
Cancel
Save