19f2944ddec232481c239f22d8d0a16cfb0713d1
[koha.git] / koha-tmpl / opac-tmpl / bootstrap / js / datatables.js
1 // These default options are for translation but can be used
2 // for any other datatables settings
3 // To use it, write:
4 //  $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, {
5 //      // other settings
6 //  } ) );
7 var dataTablesDefaults = {
8     "oLanguage": {
9         "oPaginate": {
10             "sFirst"    : __('First'),
11             "sLast"     : __('Last'),
12             "sNext"     : __('Next'),
13             "sPrevious" : __('Previous'),
14         },
15         "sEmptyTable"       : __('No data available in table'),
16         "sInfo"             : __('Showing _START_ to _END_ of _TOTAL_ entries'),
17         "sInfoEmpty"        : __('No entries to show'),
18         "sInfoFiltered"     : __('(filtered from _MAX_ total entries)'),
19         "sLengthMenu"       : __('Show _MENU_ entries'),
20         "sLoadingRecords"   : __('Loading...'),
21         "sProcessing"       : __('Processing...'),
22         "sSearch"           : __('Search:'),
23         "sZeroRecords"      : __('No matching records found'),
24         buttons: {
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.'),
27             "copySuccess": {
28                 _: __('Copied %d rows to clipboard'),
29                 1: __('Copied one row to clipboard'),
30             }
31         }
32     },
33     "dom": '<"top pager"<"table_entries"ilp><"table_controls"fB>>tr<"bottom pager"ip>',
34     "buttons": [{
35         fade: 100,
36         className: "dt_button_clear_filter",
37         titleAttr: __('Clear filter'),
38         enabled: false,
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
43                 return true;
44             }
45         },
46         action: function ( e, dt, node ) {
47             dt.search( "" ).draw("page");
48             node.addClass("disabled");
49         }
50     }],
51     "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, __('All')]],
52     "iDisplayLength": 20,
53     initComplete: function( settings) {
54         var tableId = settings.nTable.id
55         // When the DataTables search function is triggered,
56         // enable or disable the "Clear filter" button based on
57         // the presence of a search string
58         $("#" + tableId ).on( 'search.dt', function ( e, settings ) {
59             if( settings.oPreviousSearch.sSearch == "" ){
60                 $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").addClass("disabled");
61             } else {
62                 $("#" + tableId + "_wrapper").find(".dt_button_clear_filter").removeClass("disabled");
63             }
64         });
65     }
66 };
67
68
69 // Return an array of string containing the values of a particular column
70 $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
71     // check that we have a column id
72     if ( typeof iColumn == "undefined" ) return new Array();
73     // by default we only wany unique data
74     if ( typeof bUnique == "undefined" ) bUnique = true;
75     // by default we do want to only look at filtered data
76     if ( typeof bFiltered == "undefined" ) bFiltered = true;
77     // by default we do not wany to include empty values
78     if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
79     // list of rows which we're going to loop through
80     var aiRows;
81     // use only filtered rows
82     if (bFiltered == true) aiRows = oSettings.aiDisplay;
83     // use all rows
84     else aiRows = oSettings.aiDisplayMaster; // all row numbers
85
86     // set up data array
87     var asResultData = new Array();
88     for (var i=0,c=aiRows.length; i<c; i++) {
89         iRow = aiRows[i];
90         var aData = this.fnGetData(iRow);
91         var sValue = aData[iColumn];
92         // ignore empty values?
93         if (bIgnoreEmpty == true && sValue.length == 0) continue;
94         // ignore unique values?
95         else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
96         // else push the value onto the result data array
97         else asResultData.push(sValue);
98     }
99     return asResultData;
100 }
101
102 // List of unbind keys (Ctrl, Alt, Direction keys, etc.)
103 // These keys must not launch filtering
104 var blacklist_keys = new Array(0, 16, 17, 18, 37, 38, 39, 40);
105
106 // Set a filtering delay for global search field
107 jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
108     /*
109      * Inputs:      object:oSettings - dataTables settings object - automatically given
110      *              integer:iDelay - delay in milliseconds
111      * Usage:       $('#example').dataTable().fnSetFilteringDelay(250);
112      * Author:      Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
113      * License:     GPL v2 or BSD 3 point style
114      * Contact:     zygimantas.berziunas /AT\ hotmail.com
115      */
116     var
117         _that = this,
118         iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
119
120     this.each( function ( i ) {
121         $.fn.dataTableExt.iApiIndex = i;
122         var
123             $this = this,
124             oTimerId = null,
125             sPreviousSearch = null,
126             anControl = $( 'input', _that.fnSettings().aanFeatures.f );
127
128         anControl.unbind( 'keyup.DT' ).bind( 'keyup.DT', function(event) {
129             var $$this = $this;
130             if (blacklist_keys.indexOf(event.keyCode) != -1) {
131                 return this;
132             }else if ( event.keyCode == '13' ) {
133                 $.fn.dataTableExt.iApiIndex = i;
134                 _that.fnFilter( $(this).val() );
135             } else {
136                 if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
137                     window.clearTimeout(oTimerId);
138                     sPreviousSearch = anControl.val();
139                     oTimerId = window.setTimeout(function() {
140                         $.fn.dataTableExt.iApiIndex = i;
141                         _that.fnFilter( anControl.val() );
142                     }, iDelay);
143                 }
144             }
145         });
146
147         return this;
148     } );
149     return this;
150 }
151
152 // Add a filtering delay on general search and on all input (with a class 'filter')
153 jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay ) {
154     var table = this;
155     this.fnSetFilteringDelay(iDelay);
156     var filterTimerId = null;
157     $(table).find("input."+sClass).keyup(function(event) {
158       if (blacklist_keys.indexOf(event.keyCode) != -1) {
159         return this;
160       }else if ( event.keyCode == '13' ) {
161         table.fnFilter( $(this).val(), $(this).attr('data-column_num') );
162       } else {
163         window.clearTimeout(filterTimerId);
164         var input = this;
165         filterTimerId = window.setTimeout(function() {
166           table.fnFilter($(input).val(), $(input).attr('data-column_num'));
167         }, iDelay);
168       }
169     });
170     $(table).find("select."+sClass).on('change', function() {
171         table.fnFilter($(this).val(), $(this).attr('data-column_num'));
172     });
173 }
174
175 // Sorting on html contains
176 // <a href="foo.pl">bar</a> sort on 'bar'
177 function dt_overwrite_html_sorting_localeCompare() {
178     jQuery.fn.dataTableExt.oSort['html-asc']  = function(a,b) {
179         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
180         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
181         if (typeof(a.localeCompare == "function")) {
182            return a.localeCompare(b);
183         } else {
184            return (a > b) ? 1 : ((a < b) ? -1 : 0);
185         }
186     };
187
188     jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
189         a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
190         b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
191         if(typeof(b.localeCompare == "function")) {
192             return b.localeCompare(a);
193         } else {
194             return (b > a) ? 1 : ((b < a) ? -1 : 0);
195         }
196     };
197
198     jQuery.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
199         var x = a.replace( /<.*?>/g, "" );
200         var y = b.replace( /<.*?>/g, "" );
201         x = parseFloat( x );
202         y = parseFloat( y );
203         return ((x < y) ? -1 : ((x > y) ?  1 : 0));
204     };
205
206     jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
207         var x = a.replace( /<.*?>/g, "" );
208         var y = b.replace( /<.*?>/g, "" );
209         x = parseFloat( x );
210         y = parseFloat( y );
211         return ((x < y) ?  1 : ((x > y) ? -1 : 0));
212     };
213 }
214
215 $.fn.dataTableExt.oSort['num-html-asc']  = function(a,b) {
216     var x = a.replace( /<.*?>/g, "" );
217     var y = b.replace( /<.*?>/g, "" );
218     x = parseFloat( x );
219     y = parseFloat( y );
220     return ((x < y) ? -1 : ((x > y) ?  1 : 0));
221 };
222
223 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
224     var x = a.replace( /<.*?>/g, "" );
225     var y = b.replace( /<.*?>/g, "" );
226     x = parseFloat( x );
227     y = parseFloat( y );
228     return ((x < y) ?  1 : ((x > y) ? -1 : 0));
229 };
230
231 (function() {
232
233 /*
234  * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
235  * Author: Jim Palmer (based on chunking idea from Dave Koelle)
236  * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
237  * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
238  */
239 function naturalSort (a, b) {
240     var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
241         sre = /(^[ ]*|[ ]*$)/g,
242         dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
243         hre = /^0x[0-9a-f]+$/i,
244         ore = /^0/,
245         // convert all to strings and trim()
246         x = a.toString().replace(sre, '') || '',
247         y = b.toString().replace(sre, '') || '',
248         // chunk/tokenize
249         xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
250         yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
251         // numeric, hex or date detection
252         xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
253         yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
254     // first try and sort Hex codes or Dates
255     if (yD)
256         if ( xD < yD ) return -1;
257         else if ( xD > yD )  return 1;
258     // natural sorting through split numeric strings and default strings
259     for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
260         // find floats not starting with '0', string or 0 if not defined (Clint Priest)
261         var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
262         var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
263         // handle numeric vs string comparison - number < string - (Kyle Adams)
264         if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
265         // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
266         else if (typeof oFxNcL !== typeof oFyNcL) {
267             oFxNcL += '';
268             oFyNcL += '';
269         }
270         if (oFxNcL < oFyNcL) return -1;
271         if (oFxNcL > oFyNcL) return 1;
272     }
273     return 0;
274 }
275
276 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
277     "natural-asc": function ( a, b ) {
278         return naturalSort(a,b);
279     },
280
281     "natural-desc": function ( a, b ) {
282         return naturalSort(a,b) * -1;
283     }
284 } );
285
286 }());
287
288 /* Plugin to allow sorting on data stored in a span's title attribute
289  *
290  * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
291  *
292  * In DataTables config:
293  *     "aoColumns": [
294  *        { "sType": "title-string" },
295  *      ]
296  * http://datatables.net/plug-ins/sorting#hidden_title_string
297  */
298 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
299     "title-string-pre": function ( a ) {
300         var m = a.match(/title="(.*?)"/);
301         if ( null !== m && m.length ) {
302             return m[1].toLowerCase();
303         }
304         return "";
305     },
306
307     "title-string-asc": function ( a, b ) {
308         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
309     },
310
311     "title-string-desc": function ( a, b ) {
312         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
313     }
314 } );
315
316 /* Plugin to allow sorting on numeric data stored in a span's title attribute
317  *
318  * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
319  *              [% formatted currency %]
320  *     </span></td>
321  *
322  * In DataTables config:
323  *     "aoColumns": [
324  *        { "sType": "title-numeric" },
325  *      ]
326  * http://datatables.net/plug-ins/sorting#hidden_title
327  */
328 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
329     "title-numeric-pre": function ( a ) {
330         var x = a.match(/title="*(-?[0-9\.]+)/)[1];
331         return parseFloat( x );
332     },
333
334     "title-numeric-asc": function ( a, b ) {
335         return ((a < b) ? -1 : ((a > b) ? 1 : 0));
336     },
337
338     "title-numeric-desc": function ( a, b ) {
339         return ((a < b) ? 1 : ((a > b) ? -1 : 0));
340     }
341 } );
342
343 (function() {
344
345     /* Plugin to allow text sorting to ignore articles
346      *
347      * In DataTables config:
348      *     "aoColumns": [
349      *        { "sType": "anti-the" },
350      *      ]
351      * Based on the plugin found here:
352      * http://datatables.net/plug-ins/sorting#anti_the
353      * Modified to exclude HTML tags from sorting
354      * Extended to accept a string of space-separated articles
355      * from a configuration file (in English, "a," "an," and "the")
356      */
357
358     var config_exclude_articles_from_sort = __('a an the');
359     if (config_exclude_articles_from_sort){
360         var articles = config_exclude_articles_from_sort.split(" ");
361         var rpattern = "";
362         for(i=0;i<articles.length;i++){
363             rpattern += "^" + articles[i] + " ";
364             if(i < articles.length - 1){ rpattern += "|"; }
365         }
366         var re = new RegExp(rpattern, "i");
367     }
368
369     jQuery.extend( jQuery.fn.dataTableExt.oSort, {
370         "anti-the-pre": function ( a ) {
371             var x = String(a).replace( /<[\s\S]*?>/g, "" );
372             var y = x.trim();
373             var z = y.replace(re, "").toLowerCase();
374             return z;
375         },
376
377         "anti-the-asc": function ( a, b ) {
378             return ((a < b) ? -1 : ((a > b) ? 1 : 0));
379         },
380
381         "anti-the-desc": function ( a, b ) {
382             return ((a < b) ? 1 : ((a > b) ? -1 : 0));
383         }
384     });
385
386 }());
387
388 // Remove string between NSB NSB characters
389 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
390     var pattern = new RegExp("\x88.*\x89");
391     a = a.replace(pattern, "");
392     b = b.replace(pattern, "");
393     return (a > b) ? 1 : ((a < b) ? -1 : 0);
394 }
395 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
396     var pattern = new RegExp("\x88.*\x89");
397     a = a.replace(pattern, "");
398     b = b.replace(pattern, "");
399     return (b > a) ? 1 : ((b < a) ? -1 : 0);
400 }
401
402 /* Define two custom functions (asc and desc) for basket callnumber sorting */
403 jQuery.fn.dataTableExt.oSort['callnumbers-asc']  = function(x,y) {
404         var x_array = x.split("<div>");
405         var y_array = y.split("<div>");
406
407         /* Pop the first elements, they are empty strings */
408         x_array.shift();
409         y_array.shift();
410
411         x_array = jQuery.map( x_array, function( a ) {
412             return parse_callnumber( a );
413         });
414         y_array = jQuery.map( y_array, function( a ) {
415             return parse_callnumber( a );
416         });
417
418         x_array.sort();
419         y_array.sort();
420
421         x = x_array.shift();
422         y = y_array.shift();
423
424         if ( !x ) { x = ""; }
425         if ( !y ) { y = ""; }
426
427         return ((x < y) ? -1 : ((x > y) ?  1 : 0));
428 };
429
430 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
431         var x_array = x.split("<div>");
432         var y_array = y.split("<div>");
433
434         /* Pop the first elements, they are empty strings */
435         x_array.shift();
436         y_array.shift();
437
438         x_array = jQuery.map( x_array, function( a ) {
439             return parse_callnumber( a );
440         });
441         y_array = jQuery.map( y_array, function( a ) {
442             return parse_callnumber( a );
443         });
444
445         x_array.sort();
446         y_array.sort();
447
448         x = x_array.pop();
449         y = y_array.pop();
450
451         if ( !x ) { x = ""; }
452         if ( !y ) { y = ""; }
453
454         return ((x < y) ?  1 : ((x > y) ? -1 : 0));
455 };
456
457 function parse_callnumber ( html ) {
458     var array = html.split('<span class="callnumber">');
459     if ( array[1] ) {
460         array = array[1].split('</span>');
461         return array[0];
462     } else {
463         return "";
464     }
465 }
466
467 // see http://www.datatables.net/examples/advanced_init/footer_callback.html
468 function footer_column_sum( api, column_numbers ) {
469     // Remove the formatting to get integer data for summation
470     var intVal = function ( i ) {
471         if ( typeof i === 'number' ) {
472             if ( isNaN(i) ) return 0;
473             return i;
474         } else if ( typeof i === 'string' ) {
475             var value = i.replace(/[a-zA-Z ,.]/g, '')*1;
476             if ( isNaN(value) ) return 0;
477             return value;
478         }
479         return 0;
480     };
481
482
483     for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) {
484         var column_number = column_numbers[indice];
485
486         var total = 0;
487         var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount");
488         $(cells).each(function(){
489             total += intVal( $(this).html() );
490         });
491         total /= 100; // Hard-coded decimal precision
492
493         // Update footer
494         $( api.column( column_number ).footer() ).html(total.format_price());
495     };
496 }
497
498 function filterDataTable( table, column, term ){
499     if( column ){
500         table.column( column ).search( term ).draw("page");
501     } else {
502         table.search( term ).draw("page");
503     }
504 }
505
506 jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
507     console.warn(message);
508 };
509
510 (function($) {
511
512     $.fn.api = function(options, columns_settings, add_filters) {
513         var settings = null;
514         if(options) {
515             if(!options.criteria || ['contains', 'starts_with', 'ends_with', 'exact'].indexOf(options.criteria.toLowerCase()) === -1) options.criteria = 'contains';
516             options.criteria = options.criteria.toLowerCase();
517             settings = $.extend(true, {}, dataTablesDefaults, {
518                         'deferRender': true,
519                         "paging": true,
520                         'serverSide': true,
521                         'searching': true,
522                         'processing': true,
523                         'language': {
524                             'emptyTable': (options.emptyTable) ? options.emptyTable : "No data available in table"
525                         },
526                         'pagingType': 'full',
527                         'ajax': {
528                             'type': 'GET',
529                             'cache': true,
530                             'dataSrc': 'data',
531                             'beforeSend': function(xhr, settings) {
532                                 this._xhr = xhr;
533                                 if(options.embed) {
534                                     xhr.setRequestHeader('x-koha-embed', Array.isArray(options.embed)?options.embed.join(','):options.embed);
535                                 }
536                                 if(options.header_filter && options.query_parameters) {
537                                     xhr.setRequestHeader('x-koha-query', options.query_parameters);
538                                     delete options.query_parameters;
539                                 }
540                             },
541                             'dataFilter': function(data, type) {
542                                 var json = {data: JSON.parse(data)};
543                                 if(total = this._xhr.getResponseHeader('x-total-count')) {
544                                     json.recordsTotal = total;
545                                     json.recordsFiltered = total;
546                                 }
547                                 return JSON.stringify(json);
548                             },
549                             'data': function( data, settings ) {
550                                 var length = data.length;
551                                 var start  = data.start;
552
553                                 var dataSet = {
554                                     _page: Math.floor(start/length) + 1,
555                                     _per_page: length
556                                 };
557
558                                 var filter = data.search.value;
559                                 var query_parameters = settings.aoColumns
560                                 .filter(function(col) {
561                                     return col.bSearchable && typeof col.data == 'string' && (data.columns[col.idx].search.value != '' || filter != '')
562                                 })
563                                 .map(function(col) {
564                                     var part = {};
565                                     var value = data.columns[col.idx].search.value != '' ? data.columns[col.idx].search.value : filter;
566                                     part[!col.data.includes('.')?'me.'+col.data:col.data] = options.criteria === 'exact'?value:{like: (['contains', 'ends_with'].indexOf(options.criteria) !== -1?'%':'')+value+(['contains', 'starts_with'].indexOf(options.criteria) !== -1?'%':'')};
567                                     return part;
568                                 });
569
570                                 if(query_parameters.length) {
571                                     query_parameters = JSON.stringify(query_parameters.length === 1?query_parameters[0]:query_parameters);
572                                     if(options.header_filter) {
573                                         options.query_parameters = query_parameters;
574                                     } else {
575                                         dataSet.q = query_parameters;
576                                         delete options.query_parameters;
577                                     }
578                                 } else {
579                                     delete options.query_parameters;
580                                 }
581
582                                 dataSet._match = options.criteria;
583
584                                 if(options.columns) {
585                                     var order = data.order;
586                                     order.forEach(function (e,i) {
587                                         var order_col      = e.column;
588                                         var order_by       = options.columns[order_col].data;
589                                         var order_dir      = e.dir == 'asc' ? '+' : '-';
590                                         dataSet._order_by = order_dir + (!order_by.includes('.')?'me.'+order_by:order_by);
591                                     });
592                                 }
593
594                                 return dataSet;
595                             }
596                         }
597                     }, options);
598         }
599
600         var counter = 0;
601         var hidden_ids = [];
602         var included_ids = [];
603
604         $(columns_settings).each( function() {
605             var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' );
606             var used_id = settings.bKohaColumnsUseNames ? named_id : counter;
607             if ( used_id == -1 ) return;
608
609             if ( this['is_hidden'] == "1" ) {
610                 hidden_ids.push( used_id );
611             }
612             if ( this['cannot_be_toggled'] == "0" ) {
613                 included_ids.push( used_id );
614             }
615             counter++;
616         });
617
618         var exportColumns = ":visible:not(.noExport)";
619         if( settings.hasOwnProperty("exportColumns") ){
620             // A custom buttons configuration has been passed from the page
621             exportColumns = settings["exportColumns"];
622         }
623
624         var export_format = {
625             body: function ( data, row, column, node ) {
626                 var newnode = $(node);
627
628                 if ( newnode.find(".noExport").length > 0 ) {
629                     newnode = newnode.clone();
630                     newnode.find(".noExport").remove();
631                 }
632
633                 return newnode.text().replace( /\n/g, ' ' ).trim();
634             }
635         }
636
637         var export_buttons = [
638             {
639                 extend: 'excelHtml5',
640                 text: _("Excel"),
641                 exportOptions: {
642                     columns: exportColumns,
643                     format:  export_format
644                 },
645             },
646             {
647                 extend: 'csvHtml5',
648                 text: _("CSV"),
649                 exportOptions: {
650                     columns: exportColumns,
651                     format:  export_format
652                 },
653             },
654             {
655                 extend: 'copyHtml5',
656                 text: _("Copy"),
657                 exportOptions: {
658                     columns: exportColumns,
659                     format:  export_format
660                 },
661             },
662             {
663                 extend: 'print',
664                 text: _("Print"),
665                 exportOptions: {
666                     columns: exportColumns,
667                     format:  export_format
668                 },
669             }
670         ];
671
672         settings[ "buttons" ] = [
673             {
674                 fade: 100,
675                 className: "dt_button_clear_filter",
676                 titleAttr: _("Clear filter"),
677                 enabled: false,
678                 text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
679                 action: function ( e, dt, node, config ) {
680                     dt.search( "" ).draw("page");
681                     node.addClass("disabled");
682                 }
683             }
684         ];
685
686         if( included_ids.length > 0 ){
687             settings[ "buttons" ].push(
688                 {
689                     extend: 'colvis',
690                     fade: 100,
691                     columns: included_ids,
692                     className: "columns_controls",
693                     titleAttr: _("Columns settings"),
694                     text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>',
695                     exportOptions: {
696                         columns: exportColumns
697                     }
698                 }
699             );
700         }
701
702         settings[ "buttons" ].push(
703             {
704                 extend: 'collection',
705                 autoClose: true,
706                 fade: 100,
707                 className: "export_controls",
708                 titleAttr: _("Export or print"),
709                 text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>',
710                 buttons: export_buttons
711             }
712         );
713
714         if ( add_filters ) {
715             // Duplicate the table header row for columnFilter
716             thead_row = this.find('thead tr');
717             clone = thead_row.clone().addClass('filters_row');
718             clone.find("th.NoSort").html('');
719             thead_row.before(clone);
720         }
721
722         $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
723
724         return $(this).dataTable(settings);
725     };
726
727 })(jQuery);