1 // These default options are for translation but can be used
2 // for any other datatables settings
4 // $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, {
7 var dataTablesDefaults = {
10 "first" : __('First'),
13 "previous" : __('Previous'),
15 "emptyTable" : __('No data available in table'),
16 "info" : __('Showing _START_ to _END_ of _TOTAL_ entries'),
17 "infoEmpty" : __('No entries to show'),
18 "infoFiltered" : __('(filtered from _MAX_ total entries)'),
19 "lengthMenu" : __('Show _MENU_ entries'),
20 "loadingRecords" : __('Loading...'),
21 "processing" : __('Processing...'),
22 "search" : __('Search:'),
23 "zeroRecords" : __('No matching records found'),
25 "copyTitle" : __('Copy to clipboard'),
26 "copyKeys" : __('Press <i>ctrl</i> or <i>⌘</i> + <i>C</i> to copy the table data<br>to your system clipboard.<br><br>To cancel, click this message or press escape.'),
28 _: __('Copied %d rows to clipboard'),
29 1: __('Copied one row to clipboard'),
33 "dom": '<"top pager"<"table_entries"ilp><"table_controls"fB>>tr<"bottom pager"ip>',
36 className: "dt_button_clear_filter",
37 titleAttr: __('Clear filter'),
39 text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + __('Clear filter') + '</span>',
40 available: function ( dt ) {
41 // The "clear filter" button is made available if this test returns true
42 if( dt.settings()[0].aanFeatures.f ){ // aanFeatures.f is null if there is no search form
46 action: function ( e, dt, node ) {
47 dt.search( "" ).draw("page");
48 node.addClass("disabled");
51 "lengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, __('All')]],
54 initComplete: function( settings) {
55 var tableId = settings.nTable.id
56 // When the DataTables search function is triggered,
57 // enable or disable the "Clear filter" button based on
58 // the presence of a search string
59 $("#" + tableId ).on( 'search.dt', function ( e, settings ) {
60 if( settings.oPreviousSearch.sSearch == "" ){
61 $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").addClass("disabled");
63 $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").removeClass("disabled");
70 // Return an array of string containing the values of a particular column
71 $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
72 // check that we have a column id
73 if ( typeof iColumn == "undefined" ) return new Array();
74 // by default we only wany unique data
75 if ( typeof bUnique == "undefined" ) bUnique = true;
76 // by default we do want to only look at filtered data
77 if ( typeof bFiltered == "undefined" ) bFiltered = true;
78 // by default we do not wany to include empty values
79 if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
80 // list of rows which we're going to loop through
82 // use only filtered rows
83 if (bFiltered == true) aiRows = oSettings.aiDisplay;
85 else aiRows = oSettings.aiDisplayMaster; // all row numbers
88 var asResultData = new Array();
89 for (var i=0,c=aiRows.length; i<c; i++) {
91 var aData = this.fnGetData(iRow);
92 var sValue = aData[iColumn];
93 // ignore empty values?
94 if (bIgnoreEmpty == true && sValue.length == 0) continue;
95 // ignore unique values?
96 else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
97 // else push the value onto the result data array
98 else asResultData.push(sValue);
103 // List of unbind keys (Ctrl, Alt, Direction keys, etc.)
104 // These keys must not launch filtering
105 var blacklist_keys = new Array(0, 16, 17, 18, 37, 38, 39, 40);
107 // Set a filtering delay for global search field
108 jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
110 * Inputs: object:oSettings - dataTables settings object - automatically given
111 * integer:iDelay - delay in milliseconds
112 * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
113 * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
114 * License: GPL v2 or BSD 3 point style
115 * Contact: zygimantas.berziunas /AT\ hotmail.com
119 iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
121 this.each( function ( i ) {
122 $.fn.dataTableExt.iApiIndex = i;
126 sPreviousSearch = null,
127 anControl = $( 'input', _that.fnSettings().aanFeatures.f );
129 anControl.unbind( 'keyup.DT' ).bind( 'keyup.DT', function(event) {
131 if (blacklist_keys.indexOf(event.keyCode) != -1) {
133 }else if ( event.keyCode == '13' ) {
134 $.fn.dataTableExt.iApiIndex = i;
135 _that.fnFilter( $(this).val() );
137 if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
138 window.clearTimeout(oTimerId);
139 sPreviousSearch = anControl.val();
140 oTimerId = window.setTimeout(function() {
141 $.fn.dataTableExt.iApiIndex = i;
142 _that.fnFilter( anControl.val() );
153 // Add a filtering delay on general search and on all input (with a class 'filter')
154 jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay ) {
156 this.fnSetFilteringDelay(iDelay);
157 var filterTimerId = null;
158 $(table).find("input."+sClass).keyup(function(event) {
159 if (blacklist_keys.indexOf(event.keyCode) != -1) {
161 }else if ( event.keyCode == '13' ) {
162 table.fnFilter( $(this).val(), $(this).attr('data-column_num') );
164 window.clearTimeout(filterTimerId);
166 filterTimerId = window.setTimeout(function() {
167 table.fnFilter($(input).val(), $(input).attr('data-column_num'));
171 $(table).find("select."+sClass).on('change', function() {
172 table.fnFilter($(this).val(), $(this).attr('data-column_num'));
176 // Sorting on html contains
177 // <a href="foo.pl">bar</a> sort on 'bar'
178 function dt_overwrite_html_sorting_localeCompare() {
179 jQuery.fn.dataTableExt.oSort['html-asc'] = function(a,b) {
180 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
181 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
182 if (typeof(a.localeCompare == "function")) {
183 return a.localeCompare(b);
185 return (a > b) ? 1 : ((a < b) ? -1 : 0);
189 jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
190 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
191 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
192 if(typeof(b.localeCompare == "function")) {
193 return b.localeCompare(a);
195 return (b > a) ? 1 : ((b < a) ? -1 : 0);
199 jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
200 var x = a.replace( /<.*?>/g, "" );
201 var y = b.replace( /<.*?>/g, "" );
204 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
207 jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
208 var x = a.replace( /<.*?>/g, "" );
209 var y = b.replace( /<.*?>/g, "" );
212 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
216 $.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
217 var x = a.replace( /<.*?>/g, "" );
218 var y = b.replace( /<.*?>/g, "" );
221 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
224 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
225 var x = a.replace( /<.*?>/g, "" );
226 var y = b.replace( /<.*?>/g, "" );
229 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
235 * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
236 * Author: Jim Palmer (based on chunking idea from Dave Koelle)
237 * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
238 * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
240 function naturalSort (a, b) {
241 var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
242 sre = /(^[ ]*|[ ]*$)/g,
243 dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
244 hre = /^0x[0-9a-f]+$/i,
246 // convert all to strings and trim()
247 x = a.toString().replace(sre, '') || '',
248 y = b.toString().replace(sre, '') || '',
250 xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
251 yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
252 // numeric, hex or date detection
253 xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
254 yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
255 // first try and sort Hex codes or Dates
257 if ( xD < yD ) return -1;
258 else if ( xD > yD ) return 1;
259 // natural sorting through split numeric strings and default strings
260 for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
261 // find floats not starting with '0', string or 0 if not defined (Clint Priest)
262 var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
263 var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
264 // handle numeric vs string comparison - number < string - (Kyle Adams)
265 if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
266 // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
267 else if (typeof oFxNcL !== typeof oFyNcL) {
271 if (oFxNcL < oFyNcL) return -1;
272 if (oFxNcL > oFyNcL) return 1;
277 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
278 "natural-asc": function ( a, b ) {
279 return naturalSort(a,b);
282 "natural-desc": function ( a, b ) {
283 return naturalSort(a,b) * -1;
289 /* Plugin to allow sorting on data stored in a span's title attribute
291 * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
293 * In DataTables config:
295 * { "sType": "title-string" },
297 * http://datatables.net/plug-ins/sorting#hidden_title_string
299 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
300 "title-string-pre": function ( a ) {
301 var m = a.match(/title="(.*?)"/);
302 if ( null !== m && m.length ) {
303 return m[1].toLowerCase();
308 "title-string-asc": function ( a, b ) {
309 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
312 "title-string-desc": function ( a, b ) {
313 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
319 /* Plugin to allow text sorting to ignore articles
321 * In DataTables config:
323 * { "sType": "anti-the" },
325 * Based on the plugin found here:
326 * http://datatables.net/plug-ins/sorting#anti_the
327 * Modified to exclude HTML tags from sorting
328 * Extended to accept a string of space-separated articles
329 * from a configuration file (in English, "a," "an," and "the")
332 var config_exclude_articles_from_sort = __('a an the');
333 if (config_exclude_articles_from_sort){
334 var articles = config_exclude_articles_from_sort.split(" ");
336 for(i=0;i<articles.length;i++){
337 rpattern += "^" + articles[i] + " ";
338 if(i < articles.length - 1){ rpattern += "|"; }
340 var re = new RegExp(rpattern, "i");
343 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
344 "anti-the-pre": function ( a ) {
345 var x = String(a).replace( /<[\s\S]*?>/g, "" );
347 var z = y.replace(re, "").toLowerCase();
351 "anti-the-asc": function ( a, b ) {
352 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
355 "anti-the-desc": function ( a, b ) {
356 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
362 // Remove string between NSB NSB characters
363 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
364 var pattern = new RegExp("\x88.*\x89");
365 a = a.replace(pattern, "");
366 b = b.replace(pattern, "");
367 return (a > b) ? 1 : ((a < b) ? -1 : 0);
369 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
370 var pattern = new RegExp("\x88.*\x89");
371 a = a.replace(pattern, "");
372 b = b.replace(pattern, "");
373 return (b > a) ? 1 : ((b < a) ? -1 : 0);
376 /* Define two custom functions (asc and desc) for basket callnumber sorting */
377 jQuery.fn.dataTableExt.oSort['callnumbers-asc'] = function(x,y) {
378 var x_array = x.split("<div>");
379 var y_array = y.split("<div>");
381 /* Pop the first elements, they are empty strings */
385 x_array = jQuery.map( x_array, function( a ) {
386 return parse_callnumber( a );
388 y_array = jQuery.map( y_array, function( a ) {
389 return parse_callnumber( a );
398 if ( !x ) { x = ""; }
399 if ( !y ) { y = ""; }
401 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
404 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
405 var x_array = x.split("<div>");
406 var y_array = y.split("<div>");
408 /* Pop the first elements, they are empty strings */
412 x_array = jQuery.map( x_array, function( a ) {
413 return parse_callnumber( a );
415 y_array = jQuery.map( y_array, function( a ) {
416 return parse_callnumber( a );
425 if ( !x ) { x = ""; }
426 if ( !y ) { y = ""; }
428 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
431 function parse_callnumber ( html ) {
432 var array = html.split('<span class="callnumber">');
434 array = array[1].split('</span>');
441 // see http://www.datatables.net/examples/advanced_init/footer_callback.html
442 function footer_column_sum( api, column_numbers ) {
443 // Remove the formatting to get integer data for summation
444 var intVal = function ( i ) {
445 if ( typeof i === 'number' ) {
446 if ( isNaN(i) ) return 0;
448 } else if ( typeof i === 'string' ) {
449 var value = i.replace(/[a-zA-Z ,.]/g, '')*1;
450 if ( isNaN(value) ) return 0;
457 for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) {
458 var column_number = column_numbers[indice];
461 var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount");
462 var budgets_totaled = [];
463 $(cells).each(function(){ budgets_totaled.push( $(this).data('self_id') ); });
464 $(cells).each(function(){
465 if( $(this).data('parent_id') && $.inArray( $(this).data('parent_id'), budgets_totaled) > -1 ){
468 total += intVal( $(this).html() );
472 total /= 100; // Hard-coded decimal precision
475 $( api.column( column_number ).footer() ).html(total.format_price());
479 function filterDataTable( table, column, term ){
481 table.column( column ).search( term ).draw("page");
483 table.search( term ).draw("page");
487 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
488 console.warn(message);
494 * Create a new dataTables instance that uses the Koha RESTful API's as a data source
495 * @param {Object} options Please see the dataTables documentation for further details
496 * We extend the options set with the `criteria` key which allows
497 * the developer to select the match type to be applied during searches
498 * Valid keys are: `contains`, `starts_with`, `ends_with` and `exact`
499 * @param {Object} table_settings The arrayref as returned by TableSettings.GetTableSettings function available
500 * from the columns_settings template toolkit include
501 * @param {Boolean} add_filters Add a filters row as the top row of the table
502 * @param {Object} default_filters Add a set of default search filters to apply at table initialisation
503 * @return {Object} The dataTables instance
505 $.fn.kohaTable = function(options, table_settings, add_filters, default_filters) {
509 $(this).find('thead tr').clone(true).appendTo( $(this).find('thead') );
513 if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains';
514 options.criteria = options.criteria.toLowerCase();
515 settings = $.extend(true, {}, dataTablesDefaults, {
520 'pagingType': 'full_numbers',
523 'emptyTable': (options.emptyTable) ? options.emptyTable : __("No data available in table")
529 'beforeSend': function(xhr, settings) {
532 xhr.setRequestHeader('x-koha-embed', Array.isArray(options.embed)?options.embed.join(','):options.embed);
534 if(options.header_filter && options.query_parameters) {
535 xhr.setRequestHeader('x-koha-query', options.query_parameters);
536 delete options.query_parameters;
539 'dataFilter': function(data, type) {
540 var json = {data: JSON.parse(data)};
541 if (total = this._xhr.getResponseHeader('x-total-count')) {
542 json.recordsTotal = total;
543 json.recordsFiltered = total;
545 if (total = this._xhr.getResponseHeader('x-base-total-count')) {
546 json.recordsTotal = total;
548 if (draw = this._xhr.getResponseHeader('x-koha-request-id')) {
552 return JSON.stringify(json);
554 'data': function( data, settings ) {
555 var length = data.length;
556 var start = data.start;
559 _page: Math.floor(start/length) + 1,
563 function build_query(col, value){
565 // escape SQL special characters
566 value = value.replace(/(\%|\_|\\)/g, "\\$1" );
569 var attributes = col.data.split(':');
570 for (var i=0;i<attributes.length;i++){
572 var attr = attributes[i];
573 let criteria = options.criteria;
574 if ( value.match(/^\^(.*)\$$/) ) {
575 value = value.replace(/^\^/, '').replace(/\$$/, '');
578 part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact'
580 : {like: (['contains', 'ends_with'].indexOf(criteria) !== -1?'%':'') + value + (['contains', 'starts_with'].indexOf(criteria) !== -1?'%':'')};
586 var filter = data.search.value;
587 // Build query for each column filter
588 var and_query_parameters = settings.aoColumns
589 .filter(function(col) {
590 return col.bSearchable && typeof col.data == 'string' && data.columns[col.idx].search.value != ''
593 var value = data.columns[col.idx].search.value;
594 return build_query(col, value)
597 return ($.isArray(e) ? $.map(e, r) : e);
600 // Build query for the global search filter
601 var or_query_parameters = settings.aoColumns
602 .filter(function(col) {
603 return col.bSearchable && filter != ''
607 return build_query(col, value)
610 return ($.isArray(e) ? $.map(e, r) : e);
613 if ( default_filters ) {
614 let additional_filters = {};
615 for ( f in default_filters ) {
617 if ( typeof(default_filters[f]) === 'function' ) {
618 let val = default_filters[f]();
619 if ( val != undefined && val != "" ) {
623 k = f; v = default_filters[f];
626 // Pass to -or if you want a separate OR clause
627 // It's not the usual DBIC notation!
629 if (v) or_query_parameters.push(v)
630 } else if ( f == '-and' ) {
631 if (v) and_query_parameters.push(v)
633 additional_filters[k] = v;
636 if ( Object.keys(additional_filters).length ) {
637 and_query_parameters.push(additional_filters);
640 query_parameters = and_query_parameters;
641 if ( or_query_parameters.length) {
642 query_parameters.push(or_query_parameters);
645 if(query_parameters.length) {
646 query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:{"-and": query_parameters});
647 if(options.header_filter) {
648 options.query_parameters = query_parameters;
650 dataSet.q = query_parameters;
651 delete options.query_parameters;
654 delete options.query_parameters;
657 dataSet._match = options.criteria;
659 if ( data["draw"] !== undefined ) {
660 settings.ajax.headers = { 'x-koha-request-id': data.draw }
663 if(options.columns) {
664 var order = data.order;
665 var orderArray = new Array();
666 order.forEach(function (e,i) {
667 var order_col = e.column;
668 var order_by = options.columns[order_col].data;
669 order_by = order_by.split(':');
670 var order_dir = e.dir == 'asc' ? '+' : '-';
671 Array.prototype.push.apply(orderArray,order_by.map(x => order_dir + (!x.includes('.')?'me.'+x:x)));
673 dataSet._order_by = orderArray.filter((v, i, a) => a.indexOf(v) === i).join(',');
684 var included_ids = [];
687 if ( table_settings ) {
688 var columns_settings = table_settings['columns'];
689 $(columns_settings).each( function() {
690 var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' );
691 var used_id = settings.bKohaColumnsUseNames ? named_id : counter;
692 if ( used_id == -1 ) return;
694 if ( this['is_hidden'] == "1" ) {
695 hidden_ids.push( used_id );
697 if ( this['cannot_be_toggled'] == "0" ) {
698 included_ids.push( used_id );
704 var exportColumns = ":visible:not(.noExport)";
705 if( settings.hasOwnProperty("exportColumns") ){
706 // A custom buttons configuration has been passed from the page
707 exportColumns = settings["exportColumns"];
710 var export_format = {
711 body: function ( data, row, column, node ) {
712 var newnode = $(node);
714 if ( newnode.find(".noExport").length > 0 ) {
715 newnode = newnode.clone();
716 newnode.find(".noExport").remove();
719 return newnode.text().replace( /\n/g, ' ' ).trim();
723 var export_buttons = [
725 extend: 'excelHtml5',
728 columns: exportColumns,
729 format: export_format
736 columns: exportColumns,
737 format: export_format
744 columns: exportColumns,
745 format: export_format
752 columns: exportColumns,
753 format: export_format
758 settings[ "buttons" ] = [
761 className: "dt_button_clear_filter",
762 titleAttr: __("Clear filter"),
764 text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + __("Clear filter") + '</span>',
765 action: function ( e, dt, node, config ) {
766 dt.search( "" ).draw("page");
767 node.addClass("disabled");
772 if( included_ids.length > 0 ){
773 settings[ "buttons" ].push(
777 columns: included_ids,
778 className: "columns_controls",
779 titleAttr: __("Columns settings"),
780 text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + __("Columns") + '</span>',
782 columns: exportColumns
788 settings[ "buttons" ].push(
790 extend: 'collection',
793 className: "export_controls",
794 titleAttr: __("Export or print"),
795 text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + __("Export") + '</span>',
796 buttons: export_buttons
800 $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
803 settings['orderCellsTop'] = true;
806 if ( table_settings ) {
807 if ( table_settings.hasOwnProperty('default_display_length') && table_settings['default_display_length'] != null ) {
808 settings["pageLength"] = table_settings['default_display_length'];
810 if ( table_settings.hasOwnProperty('default_sort_order') && table_settings['default_sort_order'] != null ) {
811 settings["order"] = [[ table_settings['default_sort_order'], 'asc' ]];
815 var table = $(this).dataTable(settings);
819 var table_dt = table.DataTable();
820 $(this).find('thead tr:eq(1) th').each( function (i) {
821 var is_searchable = table_dt.settings()[0].aoColumns[i].bSearchable;
822 if ( is_searchable ) {
823 let input_type = 'input';
824 if ( $(this).data('filter') ) {
825 input_type = 'select'
826 let filter_type = $(this).data('filter');
827 var existing_search = table_dt.column(i).search();
828 let select = $('<select><option value=""></option></select');
830 // FIXME eval here is bad and dangerous, how do we workaround that?
831 $(eval(filter_type)).each(function(){
832 let o = $('<option value="%s">%s</option>'.format(this._id, this._str));
833 if ( existing_search == this._id ) {
834 o.prop("selected", "selected");
838 $(this).html( select );
840 var title = $(this).text();
841 var existing_search = table_dt.column(i).search();
842 if ( existing_search ) {
843 $(this).html( '<input type="text" value="%s" style="width: 100%" />'.format(existing_search) );
845 var search_title = _("%s search").format(title);
846 $(this).html( '<input type="text" placeholder="%s" style="width: 100%" />'.format(search_title) );
850 $( input_type, this ).on( 'keyup change', function () {
851 if ( table_dt.column(i).search() !== this.value ) {
852 if ( input_type == "input" ) {
855 .search( this.value )
860 .search( this.value.length ? '^'+this.value+'$' : '', true, false )
871 table.DataTable().on("column-visibility.dt", function(){
872 if( typeof columnsInit == 'function' ){
873 // This function can be created separately and used to trigger
874 // an event after the DataTable has loaded AND column visibility
875 // has been updated according to the table's configuration
878 }).columns( hidden_ids ).visible( false );