templates/js/library/data_table_wrapper/Shared/Infrastructure/DataTable/data_table_api.js line 1

Open in your IDE?
  1. class DataTableApi {
  2.     eventDispatcher = new EventDispatcher();
  3.     static EVENTS = {
  4.         ON_SEARCH_INPUT_CHANGED: 'searchInputChanged'
  5.     };
  6.     constructor(settings) {
  7.         this.api = new $.fn.dataTable.Api(settings);
  8.     }
  9.     getSearchInput() {
  10.         return $(this.api.table().container()).find('.dataTables_filter input');
  11.     }
  12.     replaceSearchInputElement() {
  13.         const searchInput = this.getSearchInput();
  14.         if (searchInput.length === 0) {
  15.             return null;
  16.         }
  17.         const newInput = searchInput.clone();
  18.         newInput.val(searchInput.val());
  19.         searchInput.replaceWith(newInput);
  20.         return newInput;
  21.     }
  22.     overrideSearchInputHandler() {
  23.         const searchInput = this.replaceSearchInputElement();
  24.         if (!searchInput) {
  25.             throw new Error('Search input element not found in the DataTable.');
  26.         }
  27.         searchInput
  28.             .off('.customDataTableSearch')
  29.             .on('keyup.customDataTableSearch search.customDataTableSearch input.customDataTableSearch', (event) => {
  30.                 this.eventDispatcher.emit(DataTableApi.EVENTS.ON_SEARCH_INPUT_CHANGED, {
  31.                     searchString: event.currentTarget.value,
  32.                     event: event
  33.                 });
  34.             });
  35.     }
  36.     search(searchString) {
  37.         this.api.search(searchString, true, false).draw();
  38.     }
  39. }