1 // These default options are for translation but can be used
2 // for any other datatables settings
3 // MSG_DT_* variables comes from datatables.inc
5 // $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, {
8 var dataTablesDefaults = {
11 "sFirst" : window.MSG_DT_FIRST || "First",
12 "sLast" : window.MSG_DT_LAST || "Last",
13 "sNext" : window.MSG_DT_NEXT || "Next",
14 "sPrevious" : window.MSG_DT_PREVIOUS || "Previous"
16 "sEmptyTable" : window.MSG_DT_EMPTY_TABLE || "No data available in table",
17 "sInfo" : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries",
18 "sInfoEmpty" : window.MSG_DT_INFO_EMPTY || "No entries to show",
19 "sInfoFiltered" : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)",
20 "sLengthMenu" : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries",
21 "sLoadingRecords" : window.MSG_DT_LOADING_RECORDS || "Loading...",
22 "sProcessing" : window.MSG_DT_PROCESSING || "Processing...",
23 "sSearch" : window.MSG_DT_SEARCH || "Search:",
24 "sZeroRecords" : window.MSG_DT_ZERO_RECORDS || "No matching records found",
26 "copyTitle" : window.MSG_DT_COPY_TITLE || "Copy to clipboard",
27 "copyKeys" : window.MSG_DT_COPY_KEYS || "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.",
29 _: window.MSG_DT_COPY_SUCCESS_X || "Copied %d rows to clipboard",
30 1: window.MSG_DT_COPY_SUCCESS_ONE || "Copied one row to clipboard"
34 "dom": '<"top pager"ilpfB>tr<"bottom pager"ip>',
37 className: "dt_button_clear_filter",
38 titleAttr: _("Clear filter"),
40 text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>',
41 available: function ( dt ) {
42 // The "clear filter" button is made available if this test returns true
43 if( dt.settings()[0].aanFeatures.f ){ // aanFeatures.f is null if there is no search form
47 action: function ( e, dt, node ) {
48 dt.search( "" ).draw("page");
49 node.addClass("disabled");
52 "aLengthMenu": [[10, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "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.oPagination.four_button = {
218 * Function: oPagination.four_button.fnInit
219 * Purpose: Initalise dom elements required for pagination with a list of the pages
221 * Inputs: object:oSettings - dataTables settings object
222 * node:nPaging - the DIV which contains this pagination control
223 * function:fnCallbackDraw - draw function which must be called on update
225 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
227 nFirst = document.createElement( 'span' );
228 nPrevious = document.createElement( 'span' );
229 nNext = document.createElement( 'span' );
230 nLast = document.createElement( 'span' );
232 nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
233 nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
234 nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
235 nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
237 nFirst.className = "paginate_button first";
238 nPrevious.className = "paginate_button previous";
239 nNext.className="paginate_button next";
240 nLast.className = "paginate_button last";
242 nPaging.appendChild( nFirst );
243 nPaging.appendChild( nPrevious );
244 nPaging.appendChild( nNext );
245 nPaging.appendChild( nLast );
247 $(nFirst).click( function () {
248 oSettings.oApi._fnPageChange( oSettings, "first" );
249 fnCallbackDraw( oSettings );
252 $(nPrevious).click( function() {
253 oSettings.oApi._fnPageChange( oSettings, "previous" );
254 fnCallbackDraw( oSettings );
257 $(nNext).click( function() {
258 oSettings.oApi._fnPageChange( oSettings, "next" );
259 fnCallbackDraw( oSettings );
262 $(nLast).click( function() {
263 oSettings.oApi._fnPageChange( oSettings, "last" );
264 fnCallbackDraw( oSettings );
267 /* Disallow text selection */
268 $(nFirst).bind( 'selectstart', function () { return false; } );
269 $(nPrevious).bind( 'selectstart', function () { return false; } );
270 $(nNext).bind( 'selectstart', function () { return false; } );
271 $(nLast).bind( 'selectstart', function () { return false; } );
275 * Function: oPagination.four_button.fnUpdate
276 * Purpose: Update the list of page buttons shows
278 * Inputs: object:oSettings - dataTables settings object
279 * function:fnCallbackDraw - draw function which must be called on update
281 "fnUpdate": function ( oSettings, fnCallbackDraw )
283 if ( !oSettings.aanFeatures.p )
288 /* Loop over each instance of the pager */
289 var an = oSettings.aanFeatures.p;
290 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
292 var buttons = an[i].getElementsByTagName('span');
293 if ( oSettings._iDisplayStart === 0 )
295 buttons[0].className = "paginate_disabled_first";
296 buttons[1].className = "paginate_disabled_previous";
300 buttons[0].className = "paginate_enabled_first";
301 buttons[1].className = "paginate_enabled_previous";
304 if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
306 buttons[2].className = "paginate_disabled_next";
307 buttons[3].className = "paginate_disabled_last";
311 buttons[2].className = "paginate_enabled_next";
312 buttons[3].className = "paginate_enabled_last";
318 $.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
319 var x = a.replace( /<.*?>/g, "" );
320 var y = b.replace( /<.*?>/g, "" );
323 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
326 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
327 var x = a.replace( /<.*?>/g, "" );
328 var y = b.replace( /<.*?>/g, "" );
331 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
337 * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
338 * Author: Jim Palmer (based on chunking idea from Dave Koelle)
339 * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
340 * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
342 function naturalSort (a, b) {
343 var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
344 sre = /(^[ ]*|[ ]*$)/g,
345 dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
346 hre = /^0x[0-9a-f]+$/i,
348 // convert all to strings and trim()
349 x = a.toString().replace(sre, '') || '',
350 y = b.toString().replace(sre, '') || '',
352 xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
353 yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
354 // numeric, hex or date detection
355 xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
356 yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
357 // first try and sort Hex codes or Dates
359 if ( xD < yD ) return -1;
360 else if ( xD > yD ) return 1;
361 // natural sorting through split numeric strings and default strings
362 for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
363 // find floats not starting with '0', string or 0 if not defined (Clint Priest)
364 var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
365 var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
366 // handle numeric vs string comparison - number < string - (Kyle Adams)
367 if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
368 // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
369 else if (typeof oFxNcL !== typeof oFyNcL) {
373 if (oFxNcL < oFyNcL) return -1;
374 if (oFxNcL > oFyNcL) return 1;
379 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
380 "natural-asc": function ( a, b ) {
381 return naturalSort(a,b);
384 "natural-desc": function ( a, b ) {
385 return naturalSort(a,b) * -1;
391 /* Plugin to allow sorting on data stored in a span's title attribute
393 * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
395 * In DataTables config:
397 * { "sType": "title-string" },
399 * http://datatables.net/plug-ins/sorting#hidden_title_string
401 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
402 "title-string-pre": function ( a ) {
403 var m = a.match(/title="(.*?)"/);
404 if ( null !== m && m.length ) {
405 return m[1].toLowerCase();
410 "title-string-asc": function ( a, b ) {
411 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
414 "title-string-desc": function ( a, b ) {
415 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
419 /* Plugin to allow sorting on numeric data stored in a span's title attribute
421 * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
422 * [% formatted currency %]
425 * In DataTables config:
427 * { "sType": "title-numeric" },
429 * http://datatables.net/plug-ins/sorting#hidden_title
431 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
432 "title-numeric-pre": function ( a ) {
433 var x = a.match(/title="*(-?[0-9\.]+)/)[1];
434 return parseFloat( x );
437 "title-numeric-asc": function ( a, b ) {
438 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
441 "title-numeric-desc": function ( a, b ) {
442 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
448 /* Plugin to allow text sorting to ignore articles
450 * In DataTables config:
452 * { "sType": "anti-the" },
454 * Based on the plugin found here:
455 * http://datatables.net/plug-ins/sorting#anti_the
456 * Modified to exclude HTML tags from sorting
457 * Extended to accept a string of space-separated articles
458 * from a configuration file (in English, "a," "an," and "the")
461 if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
462 var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
464 for(i=0;i<articles.length;i++){
465 rpattern += "^" + articles[i] + " ";
466 if(i < articles.length - 1){ rpattern += "|"; }
468 var re = new RegExp(rpattern, "i");
471 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
472 "anti-the-pre": function ( a ) {
473 var x = String(a).replace( /<[\s\S]*?>/g, "" );
475 var z = y.replace(re, "").toLowerCase();
479 "anti-the-asc": function ( a, b ) {
480 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
483 "anti-the-desc": function ( a, b ) {
484 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
490 // Remove string between NSB NSB characters
491 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
492 var pattern = new RegExp("\x88.*\x89");
493 a = a.replace(pattern, "");
494 b = b.replace(pattern, "");
495 return (a > b) ? 1 : ((a < b) ? -1 : 0);
497 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
498 var pattern = new RegExp("\x88.*\x89");
499 a = a.replace(pattern, "");
500 b = b.replace(pattern, "");
501 return (b > a) ? 1 : ((b < a) ? -1 : 0);
504 /* Define two custom functions (asc and desc) for basket callnumber sorting */
505 jQuery.fn.dataTableExt.oSort['callnumbers-asc'] = function(x,y) {
506 var x_array = x.split("<div>");
507 var y_array = y.split("<div>");
509 /* Pop the first elements, they are empty strings */
513 x_array = jQuery.map( x_array, function( a ) {
514 return parse_callnumber( a );
516 y_array = jQuery.map( y_array, function( a ) {
517 return parse_callnumber( a );
526 if ( !x ) { x = ""; }
527 if ( !y ) { y = ""; }
529 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
532 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
533 var x_array = x.split("<div>");
534 var y_array = y.split("<div>");
536 /* Pop the first elements, they are empty strings */
540 x_array = jQuery.map( x_array, function( a ) {
541 return parse_callnumber( a );
543 y_array = jQuery.map( y_array, function( a ) {
544 return parse_callnumber( a );
553 if ( !x ) { x = ""; }
554 if ( !y ) { y = ""; }
556 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
559 function parse_callnumber ( html ) {
560 var array = html.split('<span class="callnumber">');
562 array = array[1].split('</span>');
569 // see http://www.datatables.net/examples/advanced_init/footer_callback.html
570 function footer_column_sum( api, column_numbers ) {
571 // Remove the formatting to get integer data for summation
572 var intVal = function ( i ) {
573 if ( typeof i === 'number' ) {
574 if ( isNaN(i) ) return 0;
576 } else if ( typeof i === 'string' ) {
577 var value = i.replace(/[a-zA-Z ,.]/g, '')*1;
578 if ( isNaN(value) ) return 0;
585 for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) {
586 var column_number = column_numbers[indice];
589 var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount");
590 $(cells).each(function(){
591 total += intVal( $(this).html() );
593 total /= 100; // Hard-coded decimal precision
596 $( api.column( column_number ).footer() ).html(total.format_price());
600 function filterDataTable( table, column, term ){
602 table.column( column ).search( term ).draw("page");
604 table.search( term ).draw("page");