1 // These default options are for translation but can be used
2 // for any other datatables settings
3 // MSG_DT_* variables comes from datatables-strings.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 "sDom": '<"top pager"ilpf>t<"bottom pager"ip>',
27 "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, window.MSG_DT_ALL || "All"]]
31 // Return an array of string containing the values of a particular column
32 $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
33 // check that we have a column id
34 if ( typeof iColumn == "undefined" ) return new Array();
35 // by default we only wany unique data
36 if ( typeof bUnique == "undefined" ) bUnique = true;
37 // by default we do want to only look at filtered data
38 if ( typeof bFiltered == "undefined" ) bFiltered = true;
39 // by default we do not wany to include empty values
40 if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
41 // list of rows which we're going to loop through
43 // use only filtered rows
44 if (bFiltered == true) aiRows = oSettings.aiDisplay;
46 else aiRows = oSettings.aiDisplayMaster; // all row numbers
49 var asResultData = new Array();
50 for (var i=0,c=aiRows.length; i<c; i++) {
52 var aData = this.fnGetData(iRow);
53 var sValue = aData[iColumn];
54 // ignore empty values?
55 if (bIgnoreEmpty == true && sValue.length == 0) continue;
56 // ignore unique values?
57 else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
58 // else push the value onto the result data array
59 else asResultData.push(sValue);
64 // List of unbind keys (Ctrl, Alt, Direction keys, etc.)
65 // These keys must not launch filtering
66 var blacklist_keys = new Array(0, 16, 17, 18, 37, 38, 39, 40);
68 // Set a filtering delay for global search field
69 jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
71 * Inputs: object:oSettings - dataTables settings object - automatically given
72 * integer:iDelay - delay in milliseconds
73 * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
74 * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
75 * License: GPL v2 or BSD 3 point style
76 * Contact: zygimantas.berziunas /AT\ hotmail.com
80 iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
82 this.each( function ( i ) {
83 $.fn.dataTableExt.iApiIndex = i;
87 sPreviousSearch = null,
88 anControl = $( 'input', _that.fnSettings().aanFeatures.f );
90 anControl.unbind( 'keyup.DT' ).bind( 'keyup.DT', function(event) {
92 if (blacklist_keys.indexOf(event.keyCode) != -1) {
94 }else if ( event.keyCode == '13' ) {
95 $.fn.dataTableExt.iApiIndex = i;
96 _that.fnFilter( $(this).val() );
98 if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
99 window.clearTimeout(oTimerId);
100 sPreviousSearch = anControl.val();
101 oTimerId = window.setTimeout(function() {
102 $.fn.dataTableExt.iApiIndex = i;
103 _that.fnFilter( anControl.val() );
114 // Add a filtering delay on general search and on all input (with a class 'filter')
115 jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay ) {
117 this.fnSetFilteringDelay(iDelay);
118 var filterTimerId = null;
119 $(table).find("input."+sClass).keyup(function(event) {
120 if (blacklist_keys.indexOf(event.keyCode) != -1) {
122 }else if ( event.keyCode == '13' ) {
123 table.fnFilter( $(this).val(), $(this).attr('data-column_num') );
125 window.clearTimeout(filterTimerId);
127 filterTimerId = window.setTimeout(function() {
128 table.fnFilter($(input).val(), $(input).attr('data-column_num'));
134 // Useful if you want to filter on dates with 2 inputs (start date and end date)
135 // You have to include calendar.inc to use it
136 function dt_add_rangedate_filter(begindate_id, enddate_id, dateCol) {
137 $.fn.dataTableExt.afnFiltering.push(
138 function( oSettings, aData, iDataIndex ) {
140 var beginDate = Date_from_syspref($("#"+begindate_id).val()).getTime();
141 var endDate = Date_from_syspref($("#"+enddate_id).val()).getTime();
143 var data = Date_from_syspref(aData[dateCol]).getTime();
145 if ( !parseInt(beginDate) && ! parseInt(endDate) ) {
148 else if ( beginDate <= data && !parseInt(endDate) ) {
151 else if ( data <= endDate && !parseInt(beginDate) ) {
154 else if ( beginDate <= data && data <= endDate) {
162 //Sorting for dates (uk format)
163 function dt_add_type_uk_date() {
164 jQuery.fn.dataTableExt.aTypes.unshift(
167 if (sData.match(/(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20|21)\d\d/))
175 jQuery.fn.dataTableExt.oSort['uk_date-asc'] = function(a,b) {
176 var re = /(\d{2}\/\d{2}\/\d{4})/;
178 var ukDatea = RegExp.$1.split("/");
180 var ukDateb = RegExp.$1.split("/");
182 var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
183 var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
185 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
188 jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a,b) {
189 var re = /(\d{2}\/\d{2}\/\d{4})/;
191 var ukDatea = RegExp.$1.split("/");
193 var ukDateb = RegExp.$1.split("/");
195 var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
196 var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
198 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
202 // Sorting on html contains
203 // <a href="foo.pl">bar</a> sort on 'bar'
204 function dt_overwrite_html_sorting_localeCompare() {
205 jQuery.fn.dataTableExt.oSort['html-asc'] = function(a,b) {
206 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
207 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
208 if (typeof(a.localeCompare == "function")) {
209 return a.localeCompare(b);
211 return (a > b) ? 1 : ((a < b) ? -1 : 0);
215 jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
216 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
217 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
218 if(typeof(b.localeCompare == "function")) {
219 return b.localeCompare(a);
221 return (b > a) ? 1 : ((b < a) ? -1 : 0);
225 jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
226 var x = a.replace( /<.*?>/g, "" );
227 var y = b.replace( /<.*?>/g, "" );
230 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
233 jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
234 var x = a.replace( /<.*?>/g, "" );
235 var y = b.replace( /<.*?>/g, "" );
238 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
242 // Sorting on string without accentued characters
243 function dt_overwrite_string_sorting_localeCompare() {
244 jQuery.fn.dataTableExt.oSort['string-asc'] = function(a,b) {
245 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
246 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
247 if (typeof(a.localeCompare == "function")) {
248 return a.localeCompare(b);
250 return (a > b) ? 1 : ((a < b) ? -1 : 0);
254 jQuery.fn.dataTableExt.oSort['string-desc'] = function(a,b) {
255 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
256 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
257 if(typeof(b.localeCompare == "function")) {
258 return b.localeCompare(a);
260 return (b > a) ? 1 : ((b < a) ? -1 : 0);
265 // Replace a node with a html and js contain.
266 function replace_html( original_node, type ) {
267 switch ( $(original_node).attr('data-type') ) {
269 var id = $(original_node).attr("data-id");
270 var format = $(original_node).attr("data-format");
271 replace_html_date( original_node, id, format );
274 alert("_(This node can't be replaced)");
278 // Replace a node with a "From [date] To [date]" element
279 // Used on tfoot > td
280 function replace_html_date( original_node, id, format ) {
281 var node = $('<span style="white-space:nowrap">' + _("From") + '<input type="text" id="' + id + 'from" readonly="readonly" placeholder=\'' + _("Pick date") + '\' size="7" /><a title="Delete this filter" style="cursor:pointer" onclick=\'$("#' + id + 'from").val("").change();\' >×</a></span><br/><span style="white-space:nowrap">' + _("To") + '<input type="text" id="' + id + 'to" readonly="readonly" placeholder=\'' + _("Pick date") + '\' size="7" /><a title="Delete this filter" style="cursor:pointer" onclick=\'$("#' + id + 'to").val("").change();\' >×</a></span>');
282 $(original_node).replaceWith(node);
283 var script = document.createElement( 'script' );
284 script.type = 'text/javascript';
285 var script_content = "Calendar.setup({";
286 script_content += " inputField: \"" + id + "from\",";
287 script_content += " ifFormat: \"" + format + "\",";
288 script_content += " button: \"" + id + "from\",";
289 script_content += " onClose: function(){ $(\"#" + id + "from\").change(); this.hide();}";
290 script_content += " });";
291 script_content += " Calendar.setup({";
292 script_content += " inputField: \"" + id + "to\",";
293 script_content += " ifFormat: \"" + format + "\",";
294 script_content += " button: \"" + id + "to\",";
295 script_content += " onClose: function(){ $(\"#" + id + "to\").change(); this.hide();}";
296 script_content += " });";
297 script.text = script_content;
298 $(original_node).append( script );
301 $.fn.dataTableExt.oPagination.four_button = {
303 * Function: oPagination.four_button.fnInit
304 * Purpose: Initalise dom elements required for pagination with a list of the pages
306 * Inputs: object:oSettings - dataTables settings object
307 * node:nPaging - the DIV which contains this pagination control
308 * function:fnCallbackDraw - draw function which must be called on update
310 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
312 nFirst = document.createElement( 'span' );
313 nPrevious = document.createElement( 'span' );
314 nNext = document.createElement( 'span' );
315 nLast = document.createElement( 'span' );
317 nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
318 nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
319 nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
320 nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
322 nFirst.className = "paginate_button first";
323 nPrevious.className = "paginate_button previous";
324 nNext.className="paginate_button next";
325 nLast.className = "paginate_button last";
327 nPaging.appendChild( nFirst );
328 nPaging.appendChild( nPrevious );
329 nPaging.appendChild( nNext );
330 nPaging.appendChild( nLast );
332 $(nFirst).click( function () {
333 oSettings.oApi._fnPageChange( oSettings, "first" );
334 fnCallbackDraw( oSettings );
337 $(nPrevious).click( function() {
338 oSettings.oApi._fnPageChange( oSettings, "previous" );
339 fnCallbackDraw( oSettings );
342 $(nNext).click( function() {
343 oSettings.oApi._fnPageChange( oSettings, "next" );
344 fnCallbackDraw( oSettings );
347 $(nLast).click( function() {
348 oSettings.oApi._fnPageChange( oSettings, "last" );
349 fnCallbackDraw( oSettings );
352 /* Disallow text selection */
353 $(nFirst).bind( 'selectstart', function () { return false; } );
354 $(nPrevious).bind( 'selectstart', function () { return false; } );
355 $(nNext).bind( 'selectstart', function () { return false; } );
356 $(nLast).bind( 'selectstart', function () { return false; } );
360 * Function: oPagination.four_button.fnUpdate
361 * Purpose: Update the list of page buttons shows
363 * Inputs: object:oSettings - dataTables settings object
364 * function:fnCallbackDraw - draw function which must be called on update
366 "fnUpdate": function ( oSettings, fnCallbackDraw )
368 if ( !oSettings.aanFeatures.p )
373 /* Loop over each instance of the pager */
374 var an = oSettings.aanFeatures.p;
375 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
377 var buttons = an[i].getElementsByTagName('span');
378 if ( oSettings._iDisplayStart === 0 )
380 buttons[0].className = "paginate_disabled_previous";
381 buttons[1].className = "paginate_disabled_previous";
385 buttons[0].className = "paginate_enabled_previous";
386 buttons[1].className = "paginate_enabled_previous";
389 if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
391 buttons[2].className = "paginate_disabled_next";
392 buttons[3].className = "paginate_disabled_next";
396 buttons[2].className = "paginate_enabled_next";
397 buttons[3].className = "paginate_enabled_next";
403 $.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
404 var x = a.replace( /<.*?>/g, "" );
405 var y = b.replace( /<.*?>/g, "" );
408 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
411 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
412 var x = a.replace( /<.*?>/g, "" );
413 var y = b.replace( /<.*?>/g, "" );
416 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
422 * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
423 * Author: Jim Palmer (based on chunking idea from Dave Koelle)
424 * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
425 * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
427 function naturalSort (a, b) {
428 var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
429 sre = /(^[ ]*|[ ]*$)/g,
430 dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
431 hre = /^0x[0-9a-f]+$/i,
433 // convert all to strings and trim()
434 x = a.toString().replace(sre, '') || '',
435 y = b.toString().replace(sre, '') || '',
437 xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
438 yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
439 // numeric, hex or date detection
440 xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
441 yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
442 // first try and sort Hex codes or Dates
444 if ( xD < yD ) return -1;
445 else if ( xD > yD ) return 1;
446 // natural sorting through split numeric strings and default strings
447 for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
448 // find floats not starting with '0', string or 0 if not defined (Clint Priest)
449 var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
450 var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
451 // handle numeric vs string comparison - number < string - (Kyle Adams)
452 if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
453 // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
454 else if (typeof oFxNcL !== typeof oFyNcL) {
458 if (oFxNcL < oFyNcL) return -1;
459 if (oFxNcL > oFyNcL) return 1;
464 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
465 "natural-asc": function ( a, b ) {
466 return naturalSort(a,b);
469 "natural-desc": function ( a, b ) {
470 return naturalSort(a,b) * -1;
476 /* Plugin to allow sorting on data stored in a span's title attribute
478 * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
480 * In DataTables config:
482 * { "sType": "title-string" },
484 * http://datatables.net/plug-ins/sorting#hidden_title_string
486 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
487 "title-string-pre": function ( a ) {
488 return a.match(/title="(.*?)"/)[1].toLowerCase();
491 "title-string-asc": function ( a, b ) {
492 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
495 "title-string-desc": function ( a, b ) {
496 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
500 /* Plugin to allow sorting on numeric data stored in a span's title attribute
502 * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
503 * [% formatted currency %]
506 * In DataTables config:
508 * { "sType": "title-numeric" },
510 * http://datatables.net/plug-ins/sorting#hidden_title
512 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
513 "title-numeric-pre": function ( a ) {
514 var x = a.match(/title="*(-?[0-9\.]+)/)[1];
515 return parseFloat( x );
518 "title-numeric-asc": function ( a, b ) {
519 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
522 "title-numeric-desc": function ( a, b ) {
523 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
529 /* Plugin to allow text sorting to ignore articles
531 * In DataTables config:
533 * { "sType": "anti-the" },
535 * Based on the plugin found here:
536 * http://datatables.net/plug-ins/sorting#anti_the
537 * Modified to exclude HTML tags from sorting
538 * Extended to accept a string of space-separated articles
539 * from a configuration file (in English, "a," "an," and "the")
542 if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
543 var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
545 for(i=0;i<articles.length;i++){
546 rpattern += "^" + articles[i] + " ";
547 if(i < articles.length - 1){ rpattern += "|"; }
549 var re = new RegExp(rpattern, "i");
552 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
553 "anti-the-pre": function ( a ) {
554 var x = String(a).replace( /<[\s\S]*?>/g, "" );
556 var z = y.replace(re, "").toLowerCase();
560 "anti-the-asc": function ( a, b ) {
561 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
564 "anti-the-desc": function ( a, b ) {
565 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
571 // Remove string between NSB NSB characters
572 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
573 var pattern = new RegExp("\x88.*\x89");
574 a = a.replace(pattern, "");
575 b = b.replace(pattern, "");
576 return (a > b) ? 1 : ((a < b) ? -1 : 0);
578 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
579 var pattern = new RegExp("\x88.*\x89");
580 a = a.replace(pattern, "");
581 b = b.replace(pattern, "");
582 return (b > a) ? 1 : ((b < a) ? -1 : 0);
585 /* Define two custom functions (asc and desc) for basket callnumber sorting */
586 jQuery.fn.dataTableExt.oSort['callnumbers-asc'] = function(x,y) {
587 var x_array = x.split("<div>");
588 var y_array = y.split("<div>");
590 /* Pop the first elements, they are empty strings */
594 x_array = jQuery.map( x_array, function( a ) {
595 return parse_callnumber( a );
597 y_array = jQuery.map( y_array, function( a ) {
598 return parse_callnumber( a );
607 if ( !x ) { x = ""; }
608 if ( !y ) { y = ""; }
610 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
613 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
614 var x_array = x.split("<div>");
615 var y_array = y.split("<div>");
617 /* Pop the first elements, they are empty strings */
621 x_array = jQuery.map( x_array, function( a ) {
622 return parse_callnumber( a );
624 y_array = jQuery.map( y_array, function( a ) {
625 return parse_callnumber( a );
634 if ( !x ) { x = ""; }
635 if ( !y ) { y = ""; }
637 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
640 function parse_callnumber ( html ) {
641 var array = html.split('<span class="callnumber">');
643 array = array[1].split('</span>');