From 4cc9d341580596a543b9ce3018b16d78fa332c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Sat, 13 Feb 2021 09:43:24 +0000 Subject: [PATCH 1/4] Defines parameters within options --- features/alphabetSearch/dataTables.alphabetSearch.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.js b/features/alphabetSearch/dataTables.alphabetSearch.js index 2215c1f..a035754 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.js +++ b/features/alphabetSearch/dataTables.alphabetSearch.js @@ -147,6 +147,15 @@ function draw ( table, alphabet ) $.fn.dataTable.AlphabetSearch = function ( context ) { var table = new $.fn.dataTable.Api( context ); var alphabet = $('
'); + var options = $.extend({ + column: 0, + caseSensitive: false, + numbers: false + }, table.init().alphabet); + + $.fn.dataTable.AlphabetSearch.column = options.column; + $.fn.dataTable.AlphabetSearch.caseSensitive = options.caseSensitive; + $.fn.dataTable.AlphabetSearch.addNumbers = options.numbers; draw( table, alphabet ); @@ -185,7 +194,6 @@ $.fn.dataTable.AlphabetSearch = function ( context ) { }; $.fn.DataTable.AlphabetSearch = $.fn.dataTable.AlphabetSearch; -$.fn.dataTable.AlphabetSearch.column = 0; // Register a search plug-in $.fn.dataTable.ext.feature.push( { From a1b1d7fec0bc7550f7fb3f7916b7c166880e8425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Mon, 15 Feb 2021 14:30:57 +0000 Subject: [PATCH 2/4] Impovement to variables used --- .../dataTables.alphabetSearch.js | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.js b/features/alphabetSearch/dataTables.alphabetSearch.js index a035754..38b3200 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.js +++ b/features/alphabetSearch/dataTables.alphabetSearch.js @@ -49,12 +49,20 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) { return true; } - if ($.fn.dataTable.AlphabetSearch.caseSensitive) { - if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0) === context.alphabetSearch ) { + if (context.oInit.alphabet !== undefined) { + 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; } } else { - if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0).toUpperCase() === context.alphabetSearch ) { + if ( searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch ) { return true; } } @@ -64,11 +72,11 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) { // Private support methods -function bin ( data ) { +function bin ( data, options ) { var letter, bins = {}; for ( var i=0, ien=data.length ; i/g, '') @@ -90,13 +98,13 @@ function bin ( data ) { return bins; } -function draw ( table, alphabet ) +function draw ( table, alphabet, options ) { alphabet.empty(); alphabet.append( 'Search: ' ); - var columnData = table.column($.fn.dataTable.AlphabetSearch.column).data(); - var bins = bin( columnData ); + var columnData = table.column(options.column).data(); + var bins = bin( columnData, options ); $('') .data( 'letter', '' ) @@ -104,7 +112,7 @@ function draw ( table, alphabet ) .html( 'None' ) .appendTo( alphabet ); - if ($.fn.dataTable.AlphabetSearch.addNumbers) { + if (options.numbers) { for (var i = 0; i < 10; i++) { var letter = String.fromCharCode(48 + i); @@ -126,7 +134,7 @@ function draw ( table, alphabet ) .html( letter ) .appendTo( alphabet ); } - if ($.fn.dataTable.AlphabetSearch.caseSensitive === true) { + if (options.caseSensitive) { for (var i = 0; i < 26; i++) { var letter = String.fromCharCode(97 + i); @@ -153,11 +161,7 @@ $.fn.dataTable.AlphabetSearch = function ( context ) { numbers: false }, table.init().alphabet); - $.fn.dataTable.AlphabetSearch.column = options.column; - $.fn.dataTable.AlphabetSearch.caseSensitive = options.caseSensitive; - $.fn.dataTable.AlphabetSearch.addNumbers = options.numbers; - - draw( table, alphabet ); + draw( table, alphabet, options ); // Trigger a search 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 $.fn.dataTable.ext.feature.push( { fnInit: function ( settings ) { From a3a061e8bede8ae196b262c1d387a9d211718def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Mon, 15 Feb 2021 14:32:07 +0000 Subject: [PATCH 3/4] fixes spaces into tabs from the initial commit --- .../dataTables.alphabetSearch.js | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.js b/features/alphabetSearch/dataTables.alphabetSearch.js index 38b3200..549cb74 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.js +++ b/features/alphabetSearch/dataTables.alphabetSearch.js @@ -57,15 +57,15 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) { var caseSensitive = false } - if (caseSensitive) { - if ( searchData[columnId].charAt(0) === context.alphabetSearch ) { - return true; - } - } else { - if ( searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch ) { - return true; - } - } + if (caseSensitive) { + if ( searchData[columnId].charAt(0) === context.alphabetSearch ) { + return true; + } + } else { + if ( searchData[columnId].charAt(0).toUpperCase() === context.alphabetSearch ) { + return true; + } + } return false; } ); @@ -76,17 +76,17 @@ function bin ( data, options ) { var letter, bins = {}; for ( var i=0, ien=data.length ; i/g, '') - .charAt(0); - } else { - letter = data[i] - .toString() - .replace(/<.*?>/g, '') - .charAt(0).toUpperCase(); - } + if (options.caseSensitive) { + letter = data[i] + .toString() + .replace(/<.*?>/g, '') + .charAt(0); + } else { + letter = data[i] + .toString() + .replace(/<.*?>/g, '') + .charAt(0).toUpperCase(); + } if ( bins[letter] ) { bins[letter]++; } @@ -112,18 +112,18 @@ function draw ( table, alphabet, options ) .html( 'None' ) .appendTo( alphabet ); - if (options.numbers) { - for (var i = 0; i < 10; i++) { - var letter = String.fromCharCode(48 + i); - - $('') - .data('letter', letter) - .data('match-count', bins[letter] || 0) - .addClass(!bins[letter] ? 'empty' : '') - .html(letter) - .appendTo(alphabet); - } - } + if (options.numbers) { + for (var i = 0; i < 10; i++) { + var letter = String.fromCharCode(48 + i); + + $('') + .data('letter', letter) + .data('match-count', bins[letter] || 0) + .addClass(!bins[letter] ? 'empty' : '') + .html(letter) + .appendTo(alphabet); + } + } for ( var i=0 ; i<26 ; i++ ) { var letter = String.fromCharCode( 65 + i ); @@ -134,18 +134,18 @@ function draw ( table, alphabet, options ) .html( letter ) .appendTo( alphabet ); } - if (options.caseSensitive) { - for (var i = 0; i < 26; i++) { - var letter = String.fromCharCode(97 + i); - - $('') - .data('letter', letter) - .data('match-count', bins[letter] || 0) - .addClass(!bins[letter] ? 'empty' : '') - .html(letter) - .appendTo(alphabet); - } - } + if (options.caseSensitive) { + for (var i = 0; i < 26; i++) { + var letter = String.fromCharCode(97 + i); + + $('') + .data('letter', letter) + .data('match-count', bins[letter] || 0) + .addClass(!bins[letter] ? 'empty' : '') + .html(letter) + .appendTo(alphabet); + } + } $('
') .appendTo( alphabet ); From c671ab05811e96e69063f55c196a932b6668e595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Mon, 15 Feb 2021 16:00:32 +0000 Subject: [PATCH 4/4] Reverted back removal --- features/alphabetSearch/dataTables.alphabetSearch.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.js b/features/alphabetSearch/dataTables.alphabetSearch.js index 549cb74..a24a113 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.js +++ b/features/alphabetSearch/dataTables.alphabetSearch.js @@ -197,6 +197,8 @@ $.fn.dataTable.AlphabetSearch = function ( context ) { }; }; +$.fn.DataTable.AlphabetSearch = $.fn.dataTable.AlphabetSearch; + // Register a search plug-in $.fn.dataTable.ext.feature.push( { fnInit: function ( settings ) {