From 1400429289063f16387eac4cfc76ecca912a6656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 12 Feb 2021 21:06:11 +0000 Subject: [PATCH 1/4] Adds ability to choose column for search --- features/alphabetSearch/dataTables.alphabetSearch.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.js b/features/alphabetSearch/dataTables.alphabetSearch.js index a43eabc..982c5dc 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.js +++ b/features/alphabetSearch/dataTables.alphabetSearch.js @@ -11,7 +11,7 @@ * @author SpryMedia Ltd (www.sprymedia.co.uk) * @contact www.sprymedia.co.uk/contact * @copyright Copyright 2014 SpryMedia Ltd. - * + * * License MIT - http://datatables.net/license/mit * * For more detailed information please see: @@ -49,7 +49,7 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) { return true; } - if ( searchData[0].charAt(0) === context.alphabetSearch ) { + if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0).toUpperCase() === context.alphabetSearch ) { return true; } @@ -83,7 +83,7 @@ function draw ( table, alphabet ) alphabet.empty(); alphabet.append( 'Search: ' ); - var columnData = table.column(0).data(); + var columnData = table.column($.fn.dataTable.AlphabetSearch.column).data(); var bins = bin( columnData ); $('') From c83dcaae80de2f4ae0df4bc1fe47d608e6528405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 12 Feb 2021 21:14:13 +0000 Subject: [PATCH 2/4] Added caseSensitive variable --- features/alphabetSearch/dataTables.alphabetSearch.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.js b/features/alphabetSearch/dataTables.alphabetSearch.js index 982c5dc..3c5a3e7 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.js +++ b/features/alphabetSearch/dataTables.alphabetSearch.js @@ -49,9 +49,15 @@ $.fn.dataTable.ext.search.push( function ( context, searchData ) { return true; } - if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0).toUpperCase() === context.alphabetSearch ) { - return true; - } + if ($.fn.dataTable.AlphabetSearch.caseSensitive) { + if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0) === context.alphabetSearch ) { + return true; + } + } else { + if ( searchData[$.fn.dataTable.AlphabetSearch.column].charAt(0).toUpperCase() === context.alphabetSearch ) { + return true; + } + } return false; } ); From dcebee13c454dae25f8958ce6270c1ffe955ecbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 12 Feb 2021 21:35:26 +0000 Subject: [PATCH 3/4] removed width to accomodate numbers and case sensitivity --- features/alphabetSearch/dataTables.alphabetSearch.css | 1 - 1 file changed, 1 deletion(-) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.css b/features/alphabetSearch/dataTables.alphabetSearch.css index 3258e1e..abea2e0 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.css +++ b/features/alphabetSearch/dataTables.alphabetSearch.css @@ -10,7 +10,6 @@ div.alphabet span { color: #3174c7; cursor: pointer; text-align: center; - width: 3.5% } div.alphabet span:hover { From a16909ab517761a19593f211f2c58c6fed005abd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20K=C5=82ys?= Date: Fri, 12 Feb 2021 21:36:01 +0000 Subject: [PATCH 4/4] Add caseSensitive + addNumbers --- .../dataTables.alphabetSearch.js | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/features/alphabetSearch/dataTables.alphabetSearch.js b/features/alphabetSearch/dataTables.alphabetSearch.js index 3c5a3e7..2215c1f 100644 --- a/features/alphabetSearch/dataTables.alphabetSearch.js +++ b/features/alphabetSearch/dataTables.alphabetSearch.js @@ -68,11 +68,17 @@ function bin ( data ) { var letter, bins = {}; for ( var i=0, ien=data.length ; i/g, '') - .charAt(0).toUpperCase(); - + if ($.fn.dataTable.AlphabetSearch.caseSensitive) { + letter = data[i] + .toString() + .replace(/<.*?>/g, '') + .charAt(0); + } else { + letter = data[i] + .toString() + .replace(/<.*?>/g, '') + .charAt(0).toUpperCase(); + } if ( bins[letter] ) { bins[letter]++; } @@ -98,6 +104,18 @@ function draw ( table, alphabet ) .html( 'None' ) .appendTo( alphabet ); + if ($.fn.dataTable.AlphabetSearch.addNumbers) { + 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 ); @@ -108,6 +126,18 @@ function draw ( table, alphabet ) .html( letter ) .appendTo( alphabet ); } + if ($.fn.dataTable.AlphabetSearch.caseSensitive === true) { + 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 ); @@ -155,7 +185,7 @@ $.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( {