From 9e710a6743a0e801861576866a7ea9d3c35611f5 Mon Sep 17 00:00:00 2001 From: keeger Date: Mon, 10 Nov 2014 10:34:21 -0500 Subject: [PATCH 1/3] Create dataTables.searchHighlight-improved.js added .split(" ") to highlight parameter, so that search terms with multiple words are highlighted. --- .../dataTables.searchHighlight-improved.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 features/searchHighlight/dataTables.searchHighlight-improved.js diff --git a/features/searchHighlight/dataTables.searchHighlight-improved.js b/features/searchHighlight/dataTables.searchHighlight-improved.js new file mode 100644 index 0000000..3508ed0 --- /dev/null +++ b/features/searchHighlight/dataTables.searchHighlight-improved.js @@ -0,0 +1,67 @@ +/*! SearchHighlight for DataTables v1.0.0 + * 2014 SpryMedia Ltd - datatables.net/license + */ + +/** + * @summary SearchHighlight + * @description Search term highlighter for DataTables + * @version 1.0.0 + * @file dataTables.searchHighlight.js + * @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 + * + * This feature plug-in for DataTables will highlight search terms in the + * DataTable as they are entered into the main search input element, or via the + * `search()` API method. + * + * It depends upon the jQuery Highlight plug-in by Bartek Szopka: + * http://bartaz.github.io/sandbox.js/jquery.highlight.js + * + * Search highlighting in DataTables can be enabled by: + * + * * Adding the class `searchHighlight` to the HTML table + * * Setting the `searchHighlight` parameter in the DataTables initialisation to + * be true + * * Setting the `searchHighlight` parameter to be true in the DataTables + * defaults (thus causing all tables to have this feature) - i.e. + * `$.fn.dataTable.defaults.searchHighlight = true`. + * + * For more detailed information please see: + * http://datatables.net/blog/2014-10-22 + */ + +(function(window, document, $){ + + +// Listen for DataTables initialisations +$(document).on( 'init.dt.dth', function (e, settings, json) { + var table = new $.fn.dataTable.Api( settings ); + var body = $( table.table().body() ); + + if ( + $( table.table().node() ).hasClass( 'searchHighlight' ) || // table has class + settings.oInit.searchHighlight || // option specified + $.fn.dataTable.defaults.searchHighlight // default set + ) { + table + .on( 'draw.dt.dth column-visibility.dt.dth', function () { + // On each draw highlight search results, removing the old ones + body.unhighlight(); + + // Don't highlight the "not found" row + if ( table.rows( { filter: 'applied' } ).data().length ) { + body.highlight( table.search().split(" ") ); + } + } ) + .on( 'destroy', function () { + // Remove event handler + table.off( 'draw.dt.dth column-visibility.dt.dth' ); + } ); + } +} ); + + +})(window, document, jQuery); From 4b0a1999ff56315a0b79116e6ac16f91d2e9ad22 Mon Sep 17 00:00:00 2001 From: keeger Date: Mon, 10 Nov 2014 10:37:37 -0500 Subject: [PATCH 2/3] Update dataTables.searchHighlight.js added split(" ") to allow highlight to work with multiple terms --- features/searchHighlight/dataTables.searchHighlight.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/searchHighlight/dataTables.searchHighlight.js b/features/searchHighlight/dataTables.searchHighlight.js index 44d59fe..3508ed0 100644 --- a/features/searchHighlight/dataTables.searchHighlight.js +++ b/features/searchHighlight/dataTables.searchHighlight.js @@ -53,7 +53,7 @@ $(document).on( 'init.dt.dth', function (e, settings, json) { // Don't highlight the "not found" row if ( table.rows( { filter: 'applied' } ).data().length ) { - body.highlight( table.search() ); + body.highlight( table.search().split(" ") ); } } ) .on( 'destroy', function () { From ab4deee5316409a73a39e0e8f9a9097729e48f6b Mon Sep 17 00:00:00 2001 From: keeger Date: Mon, 10 Nov 2014 10:42:21 -0500 Subject: [PATCH 3/3] Delete dataTables.searchHighlight-improved.js --- .../dataTables.searchHighlight-improved.js | 67 ------------------- 1 file changed, 67 deletions(-) delete mode 100644 features/searchHighlight/dataTables.searchHighlight-improved.js diff --git a/features/searchHighlight/dataTables.searchHighlight-improved.js b/features/searchHighlight/dataTables.searchHighlight-improved.js deleted file mode 100644 index 3508ed0..0000000 --- a/features/searchHighlight/dataTables.searchHighlight-improved.js +++ /dev/null @@ -1,67 +0,0 @@ -/*! SearchHighlight for DataTables v1.0.0 - * 2014 SpryMedia Ltd - datatables.net/license - */ - -/** - * @summary SearchHighlight - * @description Search term highlighter for DataTables - * @version 1.0.0 - * @file dataTables.searchHighlight.js - * @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 - * - * This feature plug-in for DataTables will highlight search terms in the - * DataTable as they are entered into the main search input element, or via the - * `search()` API method. - * - * It depends upon the jQuery Highlight plug-in by Bartek Szopka: - * http://bartaz.github.io/sandbox.js/jquery.highlight.js - * - * Search highlighting in DataTables can be enabled by: - * - * * Adding the class `searchHighlight` to the HTML table - * * Setting the `searchHighlight` parameter in the DataTables initialisation to - * be true - * * Setting the `searchHighlight` parameter to be true in the DataTables - * defaults (thus causing all tables to have this feature) - i.e. - * `$.fn.dataTable.defaults.searchHighlight = true`. - * - * For more detailed information please see: - * http://datatables.net/blog/2014-10-22 - */ - -(function(window, document, $){ - - -// Listen for DataTables initialisations -$(document).on( 'init.dt.dth', function (e, settings, json) { - var table = new $.fn.dataTable.Api( settings ); - var body = $( table.table().body() ); - - if ( - $( table.table().node() ).hasClass( 'searchHighlight' ) || // table has class - settings.oInit.searchHighlight || // option specified - $.fn.dataTable.defaults.searchHighlight // default set - ) { - table - .on( 'draw.dt.dth column-visibility.dt.dth', function () { - // On each draw highlight search results, removing the old ones - body.unhighlight(); - - // Don't highlight the "not found" row - if ( table.rows( { filter: 'applied' } ).data().length ) { - body.highlight( table.search().split(" ") ); - } - } ) - .on( 'destroy', function () { - // Remove event handler - table.off( 'draw.dt.dth column-visibility.dt.dth' ); - } ); - } -} ); - - -})(window, document, jQuery);