Update dataTables.searchHighlight.js

Added ability to handle search terms set via option.
pull/121/head
keeger 11 years ago
parent ab4deee531
commit e938161f8b

@ -41,20 +41,30 @@ $(document).on( 'init.dt.dth', function (e, settings, json) {
var table = new $.fn.dataTable.Api( settings ); var table = new $.fn.dataTable.Api( settings );
var body = $( table.table().body() ); var body = $( table.table().body() );
var highlightWords = 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(" ") );
}
};
if ( if (
$( table.table().node() ).hasClass( 'searchHighlight' ) || // table has class $( table.table().node() ).hasClass( 'searchHighlight' ) || // table has class
settings.oInit.searchHighlight || // option specified settings.oInit.searchHighlight || // option specified
$.fn.dataTable.defaults.searchHighlight // default set $.fn.dataTable.defaults.searchHighlight // default set
) { ) {
// if the search option is set to a filter, the draw event below does not fire.
// so on init, if there is a search term, highlight.
if (table.search()) {
highlightWords();
}
table table
.on( 'draw.dt.dth column-visibility.dt.dth', function () { .on( 'draw.dt.dth column-visibility.dt.dth', function () {
// On each draw highlight search results, removing the old ones highlightWords();
body.unhighlight();
// Don't highlight the "not found" row
if ( table.rows( { filter: 'applied' } ).data().length ) {
body.highlight( table.search().split(" ") );
}
} ) } )
.on( 'destroy', function () { .on( 'destroy', function () {
// Remove event handler // Remove event handler

Loading…
Cancel
Save