Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dataTables.searchHighlight.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*! SearchHighlight for DataTables v1.0.1
  2. * 2014 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * @summary SearchHighlight
  6. * @description Search term highlighter for DataTables
  7. * @version 1.0.1
  8. * @file dataTables.searchHighlight.js
  9. * @author SpryMedia Ltd (www.sprymedia.co.uk)
  10. * @contact www.sprymedia.co.uk/contact
  11. * @copyright Copyright 2014 SpryMedia Ltd.
  12. *
  13. * License MIT - http://datatables.net/license/mit
  14. *
  15. * This feature plug-in for DataTables will highlight search terms in the
  16. * DataTable as they are entered into the main search input element, or via the
  17. * `search()` API method.
  18. *
  19. * It depends upon the jQuery Highlight plug-in by Bartek Szopka:
  20. * http://bartaz.github.io/sandbox.js/jquery.highlight.js
  21. *
  22. * Search highlighting in DataTables can be enabled by:
  23. *
  24. * * Adding the class `searchHighlight` to the HTML table
  25. * * Setting the `searchHighlight` parameter in the DataTables initialisation to
  26. * be true
  27. * * Setting the `searchHighlight` parameter to be true in the DataTables
  28. * defaults (thus causing all tables to have this feature) - i.e.
  29. * `$.fn.dataTable.defaults.searchHighlight = true`.
  30. *
  31. * For more detailed information please see:
  32. * http://datatables.net/blog/2014-10-22
  33. */
  34. (function(window, document, $){
  35. function highlight( body, table )
  36. {
  37. // Removing the old highlighting first
  38. body.unhighlight();
  39. // Don't highlight the "not found" row, so we get the rows using the api
  40. if ( table.rows( { filter: 'applied' } ).data().length ) {
  41. body.highlight( $.trim( table.search() ).split(/\s+/) );
  42. }
  43. }
  44. // Listen for DataTables initialisations
  45. $(document).on( 'init.dt.dth', function (e, settings, json) {
  46. if ( e.namespace !== 'dt' ) {
  47. return;
  48. }
  49. var table = new $.fn.dataTable.Api( settings );
  50. var body = $( table.table().body() );
  51. if (
  52. $( table.table().node() ).hasClass( 'searchHighlight' ) || // table has class
  53. settings.oInit.searchHighlight || // option specified
  54. $.fn.dataTable.defaults.searchHighlight // default set
  55. ) {
  56. table
  57. .on( 'draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth', function () {
  58. highlight( body, table );
  59. } )
  60. .on( 'destroy', function () {
  61. // Remove event handler
  62. table.off( 'draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth' );
  63. } );
  64. // initial highlight for state saved conditions and initial states
  65. if ( table.search() ) {
  66. highlight( body, table );
  67. }
  68. }
  69. } );
  70. })(window, document, jQuery);