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/9] 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/9] 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/9] 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/9] 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( { 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 5/9] 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 6/9] 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 7/9] 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 8/9] 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 ) { From e75a62a99b096d4195cc3f7881c282fde555da9f Mon Sep 17 00:00:00 2001 From: Allan Jardine Date: Tue, 16 Feb 2021 17:18:39 +0000 Subject: [PATCH 9/9] Renderer: Multi renderer https://datatables.net/forums/discussion/67030/how-to-use-multiple-renderers#latest --- dataRender/multi.js | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 dataRender/multi.js diff --git a/dataRender/multi.js b/dataRender/multi.js new file mode 100644 index 0000000..43a495e --- /dev/null +++ b/dataRender/multi.js @@ -0,0 +1,79 @@ +/** + * This renderer doesn't format the output itself, but rather allows multiple + * renderers to be easily called, which will render the content in sequence. + * + * Pass the renderers you wish to chain together as elements in an array to + * this function. Important - you should pass the renderer as if you were + * going to give it to the `render` property directly (i.e. if it is just a + * simple function, don't execute it). + * + * @name multi + * @summary Use multiple renderers + * @author [Allan Jardine](http://datatables.net) + * @requires DataTables 1.10+ + * + * @example + * // Convert dates using moment renderer and ensure they are HTML safe + * $('#example').DataTable( { + * columnDefs: [ { + * targets: 1, + * render: $.fn.dataTable.render.multi( [ + * $.fn.dataTable.render.moment( 'Do MMM YYYY' ), + * $.fn.dataTable.render.text(), + * ] ) + * } ] + * } ); + */ + + +// UMD +(function( factory ) { + "use strict"; + + if ( typeof define === 'function' && define.amd ) { + // AMD + define( ['jquery'], function ( $ ) { + return factory( $, window, document ); + } ); + } + else if ( typeof exports === 'object' ) { + // CommonJS + module.exports = function (root, $) { + if ( ! root ) { + root = window; + } + + if ( ! $ ) { + $ = typeof window !== 'undefined' ? + require('jquery') : + require('jquery')( root ); + } + + return factory( $, root, root.document ); + }; + } + else { + // Browser + factory( jQuery, window, document ); + } +} +(function( $, window, document ) { + + +$.fn.dataTable.render.multi = function (renderArray) { + return function (d, type, row, meta) { + for (var r = 0; r < renderArray.length; r++) { + if (typeof renderArray[r] === "function") { + d = renderArray[r](d, type, row, meta); + } else if (typeof renderArray[r][type] === "function") { + d = renderArray[r][type](d, type, row, meta); + } else if (typeof renderArray[r]._ === "function") { + d = renderArray[r]._(d, type, row, meta); + } + } + return d; + }; +}; + + +}));