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, 20, 50, 100, -1], [10, 20, 50, 100, window.MSG_DT_ALL || "All"]],
32 // Return an array of string containing the values of a particular column
33 $.fn.dataTableExt.oApi.fnGetColumnData = function ( oSettings, iColumn, bUnique, bFiltered, bIgnoreEmpty ) {
34 // check that we have a column id
35 if ( typeof iColumn == "undefined" ) return new Array();
36 // by default we only wany unique data
37 if ( typeof bUnique == "undefined" ) bUnique = true;
38 // by default we do want to only look at filtered data
39 if ( typeof bFiltered == "undefined" ) bFiltered = true;
40 // by default we do not wany to include empty values
41 if ( typeof bIgnoreEmpty == "undefined" ) bIgnoreEmpty = true;
42 // list of rows which we're going to loop through
44 // use only filtered rows
45 if (bFiltered == true) aiRows = oSettings.aiDisplay;
47 else aiRows = oSettings.aiDisplayMaster; // all row numbers
50 var asResultData = new Array();
51 for (var i=0,c=aiRows.length; i<c; i++) {
53 var aData = this.fnGetData(iRow);
54 var sValue = aData[iColumn];
55 // ignore empty values?
56 if (bIgnoreEmpty == true && sValue.length == 0) continue;
57 // ignore unique values?
58 else if (bUnique == true && jQuery.inArray(sValue, asResultData) > -1) continue;
59 // else push the value onto the result data array
60 else asResultData.push(sValue);
65 // List of unbind keys (Ctrl, Alt, Direction keys, etc.)
66 // These keys must not launch filtering
67 var blacklist_keys = new Array(0, 16, 17, 18, 37, 38, 39, 40);
69 // Set a filtering delay for global search field
70 jQuery.fn.dataTableExt.oApi.fnSetFilteringDelay = function ( oSettings, iDelay ) {
72 * Inputs: object:oSettings - dataTables settings object - automatically given
73 * integer:iDelay - delay in milliseconds
74 * Usage: $('#example').dataTable().fnSetFilteringDelay(250);
75 * Author: Zygimantas Berziunas (www.zygimantas.com) and Allan Jardine
76 * License: GPL v2 or BSD 3 point style
77 * Contact: zygimantas.berziunas /AT\ hotmail.com
81 iDelay = (typeof iDelay == 'undefined') ? 250 : iDelay;
83 this.each( function ( i ) {
84 $.fn.dataTableExt.iApiIndex = i;
88 sPreviousSearch = null,
89 anControl = $( 'input', _that.fnSettings().aanFeatures.f );
91 anControl.unbind( 'keyup.DT' ).bind( 'keyup.DT', function(event) {
93 if (blacklist_keys.indexOf(event.keyCode) != -1) {
95 }else if ( event.keyCode == '13' ) {
96 $.fn.dataTableExt.iApiIndex = i;
97 _that.fnFilter( $(this).val() );
99 if (sPreviousSearch === null || sPreviousSearch != anControl.val()) {
100 window.clearTimeout(oTimerId);
101 sPreviousSearch = anControl.val();
102 oTimerId = window.setTimeout(function() {
103 $.fn.dataTableExt.iApiIndex = i;
104 _that.fnFilter( anControl.val() );
115 // Add a filtering delay on general search and on all input (with a class 'filter')
116 jQuery.fn.dataTableExt.oApi.fnAddFilters = function ( oSettings, sClass, iDelay ) {
118 this.fnSetFilteringDelay(iDelay);
119 var filterTimerId = null;
120 $(table).find("input."+sClass).keyup(function(event) {
121 if (blacklist_keys.indexOf(event.keyCode) != -1) {
123 }else if ( event.keyCode == '13' ) {
124 table.fnFilter( $(this).val(), $(this).attr('data-column_num') );
126 window.clearTimeout(filterTimerId);
128 filterTimerId = window.setTimeout(function() {
129 table.fnFilter($(input).val(), $(input).attr('data-column_num'));
135 // Useful if you want to filter on dates with 2 inputs (start date and end date)
136 // You have to include calendar.inc to use it
137 function dt_add_rangedate_filter(begindate_id, enddate_id, dateCol) {
138 $.fn.dataTableExt.afnFiltering.push(
139 function( oSettings, aData, iDataIndex ) {
141 var beginDate = Date_from_syspref($("#"+begindate_id).val()).getTime();
142 var endDate = Date_from_syspref($("#"+enddate_id).val()).getTime();
144 var data = Date_from_syspref(aData[dateCol]).getTime();
146 if ( !parseInt(beginDate) && ! parseInt(endDate) ) {
149 else if ( beginDate <= data && !parseInt(endDate) ) {
152 else if ( data <= endDate && !parseInt(beginDate) ) {
155 else if ( beginDate <= data && data <= endDate) {
163 //Sorting for dates (uk format)
164 function dt_add_type_uk_date() {
165 jQuery.fn.dataTableExt.aTypes.unshift(
168 if (sData.match(/(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/(19|20|21)\d\d/))
176 jQuery.fn.dataTableExt.oSort['uk_date-asc'] = function(a,b) {
177 var re = /(\d{2}\/\d{2}\/\d{4})/;
179 var ukDatea = RegExp.$1.split("/");
181 var ukDateb = RegExp.$1.split("/");
183 var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
184 var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
186 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
189 jQuery.fn.dataTableExt.oSort['uk_date-desc'] = function(a,b) {
190 var re = /(\d{2}\/\d{2}\/\d{4})/;
192 var ukDatea = RegExp.$1.split("/");
194 var ukDateb = RegExp.$1.split("/");
196 var x = (ukDatea[2] + ukDatea[1] + ukDatea[0]) * 1;
197 var y = (ukDateb[2] + ukDateb[1] + ukDateb[0]) * 1;
199 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
203 // Sorting on html contains
204 // <a href="foo.pl">bar</a> sort on 'bar'
205 function dt_overwrite_html_sorting_localeCompare() {
206 jQuery.fn.dataTableExt.oSort['html-asc'] = function(a,b) {
207 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
208 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
209 if (typeof(a.localeCompare == "function")) {
210 return a.localeCompare(b);
212 return (a > b) ? 1 : ((a < b) ? -1 : 0);
216 jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
217 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
218 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
219 if(typeof(b.localeCompare == "function")) {
220 return b.localeCompare(a);
222 return (b > a) ? 1 : ((b < a) ? -1 : 0);
226 jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
227 var x = a.replace( /<.*?>/g, "" );
228 var y = b.replace( /<.*?>/g, "" );
231 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
234 jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
235 var x = a.replace( /<.*?>/g, "" );
236 var y = b.replace( /<.*?>/g, "" );
239 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
243 // Sorting on string without accentued characters
244 function dt_overwrite_string_sorting_localeCompare() {
245 jQuery.fn.dataTableExt.oSort['string-asc'] = function(a,b) {
246 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
247 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
248 if (typeof(a.localeCompare == "function")) {
249 return a.localeCompare(b);
251 return (a > b) ? 1 : ((a < b) ? -1 : 0);
255 jQuery.fn.dataTableExt.oSort['string-desc'] = function(a,b) {
256 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
257 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
258 if(typeof(b.localeCompare == "function")) {
259 return b.localeCompare(a);
261 return (b > a) ? 1 : ((b < a) ? -1 : 0);
266 // Replace a node with a html and js contain.
267 function replace_html( original_node, type ) {
268 switch ( $(original_node).attr('data-type') ) {
270 var id = $(original_node).attr("data-id");
271 var format = $(original_node).attr("data-format");
272 replace_html_date( original_node, id, format );
275 alert("_(This node can't be replaced)");
279 // Replace a node with a "From [date] To [date]" element
280 // Used on tfoot > td
281 function replace_html_date( original_node, id, format ) {
282 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>');
283 $(original_node).replaceWith(node);
284 var script = document.createElement( 'script' );
285 script.type = 'text/javascript';
286 var script_content = "Calendar.setup({";
287 script_content += " inputField: \"" + id + "from\",";
288 script_content += " ifFormat: \"" + format + "\",";
289 script_content += " button: \"" + id + "from\",";
290 script_content += " onClose: function(){ $(\"#" + id + "from\").change(); this.hide();}";
291 script_content += " });";
292 script_content += " Calendar.setup({";
293 script_content += " inputField: \"" + id + "to\",";
294 script_content += " ifFormat: \"" + format + "\",";
295 script_content += " button: \"" + id + "to\",";
296 script_content += " onClose: function(){ $(\"#" + id + "to\").change(); this.hide();}";
297 script_content += " });";
298 script.text = script_content;
299 $(original_node).append( script );
302 $.fn.dataTableExt.oPagination.four_button = {
304 * Function: oPagination.four_button.fnInit
305 * Purpose: Initalise dom elements required for pagination with a list of the pages
307 * Inputs: object:oSettings - dataTables settings object
308 * node:nPaging - the DIV which contains this pagination control
309 * function:fnCallbackDraw - draw function which must be called on update
311 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
313 nFirst = document.createElement( 'span' );
314 nPrevious = document.createElement( 'span' );
315 nNext = document.createElement( 'span' );
316 nLast = document.createElement( 'span' );
318 nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
319 nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
320 nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
321 nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
323 nFirst.className = "paginate_button first";
324 nPrevious.className = "paginate_button previous";
325 nNext.className="paginate_button next";
326 nLast.className = "paginate_button last";
328 nPaging.appendChild( nFirst );
329 nPaging.appendChild( nPrevious );
330 nPaging.appendChild( nNext );
331 nPaging.appendChild( nLast );
333 $(nFirst).click( function () {
334 oSettings.oApi._fnPageChange( oSettings, "first" );
335 fnCallbackDraw( oSettings );
338 $(nPrevious).click( function() {
339 oSettings.oApi._fnPageChange( oSettings, "previous" );
340 fnCallbackDraw( oSettings );
343 $(nNext).click( function() {
344 oSettings.oApi._fnPageChange( oSettings, "next" );
345 fnCallbackDraw( oSettings );
348 $(nLast).click( function() {
349 oSettings.oApi._fnPageChange( oSettings, "last" );
350 fnCallbackDraw( oSettings );
353 /* Disallow text selection */
354 $(nFirst).bind( 'selectstart', function () { return false; } );
355 $(nPrevious).bind( 'selectstart', function () { return false; } );
356 $(nNext).bind( 'selectstart', function () { return false; } );
357 $(nLast).bind( 'selectstart', function () { return false; } );
361 * Function: oPagination.four_button.fnUpdate
362 * Purpose: Update the list of page buttons shows
364 * Inputs: object:oSettings - dataTables settings object
365 * function:fnCallbackDraw - draw function which must be called on update
367 "fnUpdate": function ( oSettings, fnCallbackDraw )
369 if ( !oSettings.aanFeatures.p )
374 /* Loop over each instance of the pager */
375 var an = oSettings.aanFeatures.p;
376 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
378 var buttons = an[i].getElementsByTagName('span');
379 if ( oSettings._iDisplayStart === 0 )
381 buttons[0].className = "paginate_disabled_previous";
382 buttons[1].className = "paginate_disabled_previous";
386 buttons[0].className = "paginate_enabled_previous";
387 buttons[1].className = "paginate_enabled_previous";
390 if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
392 buttons[2].className = "paginate_disabled_next";
393 buttons[3].className = "paginate_disabled_next";
397 buttons[2].className = "paginate_enabled_next";
398 buttons[3].className = "paginate_enabled_next";
404 $.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
405 var x = a.replace( /<.*?>/g, "" );
406 var y = b.replace( /<.*?>/g, "" );
409 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
412 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
413 var x = a.replace( /<.*?>/g, "" );
414 var y = b.replace( /<.*?>/g, "" );
417 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
423 * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
424 * Author: Jim Palmer (based on chunking idea from Dave Koelle)
425 * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
426 * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
428 function naturalSort (a, b) {
429 var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
430 sre = /(^[ ]*|[ ]*$)/g,
431 dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
432 hre = /^0x[0-9a-f]+$/i,
434 // convert all to strings and trim()
435 x = a.toString().replace(sre, '') || '',
436 y = b.toString().replace(sre, '') || '',
438 xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
439 yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
440 // numeric, hex or date detection
441 xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
442 yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
443 // first try and sort Hex codes or Dates
445 if ( xD < yD ) return -1;
446 else if ( xD > yD ) return 1;
447 // natural sorting through split numeric strings and default strings
448 for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
449 // find floats not starting with '0', string or 0 if not defined (Clint Priest)
450 var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
451 var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
452 // handle numeric vs string comparison - number < string - (Kyle Adams)
453 if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
454 // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
455 else if (typeof oFxNcL !== typeof oFyNcL) {
459 if (oFxNcL < oFyNcL) return -1;
460 if (oFxNcL > oFyNcL) return 1;
465 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
466 "natural-asc": function ( a, b ) {
467 return naturalSort(a,b);
470 "natural-desc": function ( a, b ) {
471 return naturalSort(a,b) * -1;
477 /* Plugin to allow sorting on data stored in a span's title attribute
479 * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
481 * In DataTables config:
483 * { "sType": "title-string" },
485 * http://datatables.net/plug-ins/sorting#hidden_title_string
487 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
488 "title-string-pre": function ( a ) {
489 return a.match(/title="(.*?)"/)[1].toLowerCase();
492 "title-string-asc": function ( a, b ) {
493 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
496 "title-string-desc": function ( a, b ) {
497 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
501 /* Plugin to allow sorting on numeric data stored in a span's title attribute
503 * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
504 * [% formatted currency %]
507 * In DataTables config:
509 * { "sType": "title-numeric" },
511 * http://datatables.net/plug-ins/sorting#hidden_title
513 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
514 "title-numeric-pre": function ( a ) {
515 var x = a.match(/title="*(-?[0-9\.]+)/)[1];
516 return parseFloat( x );
519 "title-numeric-asc": function ( a, b ) {
520 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
523 "title-numeric-desc": function ( a, b ) {
524 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
530 /* Plugin to allow text sorting to ignore articles
532 * In DataTables config:
534 * { "sType": "anti-the" },
536 * Based on the plugin found here:
537 * http://datatables.net/plug-ins/sorting#anti_the
538 * Modified to exclude HTML tags from sorting
539 * Extended to accept a string of space-separated articles
540 * from a configuration file (in English, "a," "an," and "the")
543 if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
544 var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
546 for(i=0;i<articles.length;i++){
547 rpattern += "^" + articles[i] + " ";
548 if(i < articles.length - 1){ rpattern += "|"; }
550 var re = new RegExp(rpattern, "i");
553 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
554 "anti-the-pre": function ( a ) {
555 var x = String(a).replace( /<[\s\S]*?>/g, "" );
557 var z = y.replace(re, "").toLowerCase();
561 "anti-the-asc": function ( a, b ) {
562 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
565 "anti-the-desc": function ( a, b ) {
566 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
572 // Remove string between NSB NSB characters
573 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
574 var pattern = new RegExp("\x88.*\x89");
575 a = a.replace(pattern, "");
576 b = b.replace(pattern, "");
577 return (a > b) ? 1 : ((a < b) ? -1 : 0);
579 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
580 var pattern = new RegExp("\x88.*\x89");
581 a = a.replace(pattern, "");
582 b = b.replace(pattern, "");
583 return (b > a) ? 1 : ((b < a) ? -1 : 0);
586 /* Define two custom functions (asc and desc) for basket callnumber sorting */
587 jQuery.fn.dataTableExt.oSort['callnumbers-asc'] = function(x,y) {
588 var x_array = x.split("<div>");
589 var y_array = y.split("<div>");
591 /* Pop the first elements, they are empty strings */
595 x_array = jQuery.map( x_array, function( a ) {
596 return parse_callnumber( a );
598 y_array = jQuery.map( y_array, function( a ) {
599 return parse_callnumber( a );
608 if ( !x ) { x = ""; }
609 if ( !y ) { y = ""; }
611 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
614 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
615 var x_array = x.split("<div>");
616 var y_array = y.split("<div>");
618 /* Pop the first elements, they are empty strings */
622 x_array = jQuery.map( x_array, function( a ) {
623 return parse_callnumber( a );
625 y_array = jQuery.map( y_array, function( a ) {
626 return parse_callnumber( a );
635 if ( !x ) { x = ""; }
636 if ( !y ) { y = ""; }
638 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
641 function parse_callnumber ( html ) {
642 var array = html.split('<span class="callnumber">');
644 array = array[1].split('</span>');