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>tr<"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 on html contains
164 // <a href="foo.pl">bar</a> sort on 'bar'
165 function dt_overwrite_html_sorting_localeCompare() {
166 jQuery.fn.dataTableExt.oSort['html-asc'] = function(a,b) {
167 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
168 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
169 if (typeof(a.localeCompare == "function")) {
170 return a.localeCompare(b);
172 return (a > b) ? 1 : ((a < b) ? -1 : 0);
176 jQuery.fn.dataTableExt.oSort['html-desc'] = function(a,b) {
177 a = a.replace(/<.*?>/g, "").replace(/\s+/g, " ");
178 b = b.replace(/<.*?>/g, "").replace(/\s+/g, " ");
179 if(typeof(b.localeCompare == "function")) {
180 return b.localeCompare(a);
182 return (b > a) ? 1 : ((b < a) ? -1 : 0);
186 jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
187 var x = a.replace( /<.*?>/g, "" );
188 var y = b.replace( /<.*?>/g, "" );
191 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
194 jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
195 var x = a.replace( /<.*?>/g, "" );
196 var y = b.replace( /<.*?>/g, "" );
199 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
203 // Sorting on string without accentued characters
204 function dt_overwrite_string_sorting_localeCompare() {
205 jQuery.fn.dataTableExt.oSort['string-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['string-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);
226 // Replace a node with a html and js contain.
227 function replace_html( original_node, type ) {
228 switch ( $(original_node).attr('data-type') ) {
230 var id = $(original_node).attr("data-id");
231 var format = $(original_node).attr("data-format");
232 replace_html_date( original_node, id, format );
235 alert("_(This node can't be replaced)");
239 // Replace a node with a "From [date] To [date]" element
240 // Used on tfoot > td
241 function replace_html_date( original_node, id, format ) {
242 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>');
243 $(original_node).replaceWith(node);
244 var script = document.createElement( 'script' );
245 script.type = 'text/javascript';
246 var script_content = "Calendar.setup({";
247 script_content += " inputField: \"" + id + "from\",";
248 script_content += " ifFormat: \"" + format + "\",";
249 script_content += " button: \"" + id + "from\",";
250 script_content += " onClose: function(){ $(\"#" + id + "from\").change(); this.hide();}";
251 script_content += " });";
252 script_content += " Calendar.setup({";
253 script_content += " inputField: \"" + id + "to\",";
254 script_content += " ifFormat: \"" + format + "\",";
255 script_content += " button: \"" + id + "to\",";
256 script_content += " onClose: function(){ $(\"#" + id + "to\").change(); this.hide();}";
257 script_content += " });";
258 script.text = script_content;
259 $(original_node).append( script );
262 $.fn.dataTableExt.oPagination.four_button = {
264 * Function: oPagination.four_button.fnInit
265 * Purpose: Initalise dom elements required for pagination with a list of the pages
267 * Inputs: object:oSettings - dataTables settings object
268 * node:nPaging - the DIV which contains this pagination control
269 * function:fnCallbackDraw - draw function which must be called on update
271 "fnInit": function ( oSettings, nPaging, fnCallbackDraw )
273 nFirst = document.createElement( 'span' );
274 nPrevious = document.createElement( 'span' );
275 nNext = document.createElement( 'span' );
276 nLast = document.createElement( 'span' );
278 nFirst.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sFirst ) );
279 nPrevious.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sPrevious ) );
280 nNext.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sNext ) );
281 nLast.appendChild( document.createTextNode( oSettings.oLanguage.oPaginate.sLast ) );
283 nFirst.className = "paginate_button first";
284 nPrevious.className = "paginate_button previous";
285 nNext.className="paginate_button next";
286 nLast.className = "paginate_button last";
288 nPaging.appendChild( nFirst );
289 nPaging.appendChild( nPrevious );
290 nPaging.appendChild( nNext );
291 nPaging.appendChild( nLast );
293 $(nFirst).click( function () {
294 oSettings.oApi._fnPageChange( oSettings, "first" );
295 fnCallbackDraw( oSettings );
298 $(nPrevious).click( function() {
299 oSettings.oApi._fnPageChange( oSettings, "previous" );
300 fnCallbackDraw( oSettings );
303 $(nNext).click( function() {
304 oSettings.oApi._fnPageChange( oSettings, "next" );
305 fnCallbackDraw( oSettings );
308 $(nLast).click( function() {
309 oSettings.oApi._fnPageChange( oSettings, "last" );
310 fnCallbackDraw( oSettings );
313 /* Disallow text selection */
314 $(nFirst).bind( 'selectstart', function () { return false; } );
315 $(nPrevious).bind( 'selectstart', function () { return false; } );
316 $(nNext).bind( 'selectstart', function () { return false; } );
317 $(nLast).bind( 'selectstart', function () { return false; } );
321 * Function: oPagination.four_button.fnUpdate
322 * Purpose: Update the list of page buttons shows
324 * Inputs: object:oSettings - dataTables settings object
325 * function:fnCallbackDraw - draw function which must be called on update
327 "fnUpdate": function ( oSettings, fnCallbackDraw )
329 if ( !oSettings.aanFeatures.p )
334 /* Loop over each instance of the pager */
335 var an = oSettings.aanFeatures.p;
336 for ( var i=0, iLen=an.length ; i<iLen ; i++ )
338 var buttons = an[i].getElementsByTagName('span');
339 if ( oSettings._iDisplayStart === 0 )
341 buttons[0].className = "paginate_disabled_previous";
342 buttons[1].className = "paginate_disabled_previous";
346 buttons[0].className = "paginate_enabled_previous";
347 buttons[1].className = "paginate_enabled_previous";
350 if ( oSettings.fnDisplayEnd() == oSettings.fnRecordsDisplay() )
352 buttons[2].className = "paginate_disabled_next";
353 buttons[3].className = "paginate_disabled_next";
357 buttons[2].className = "paginate_enabled_next";
358 buttons[3].className = "paginate_enabled_next";
364 $.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) {
365 var x = a.replace( /<.*?>/g, "" );
366 var y = b.replace( /<.*?>/g, "" );
369 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
372 $.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) {
373 var x = a.replace( /<.*?>/g, "" );
374 var y = b.replace( /<.*?>/g, "" );
377 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
383 * Natural Sort algorithm for Javascript - Version 0.7 - Released under MIT license
384 * Author: Jim Palmer (based on chunking idea from Dave Koelle)
385 * Contributors: Mike Grier (mgrier.com), Clint Priest, Kyle Adams, guillermo
386 * See: http://js-naturalsort.googlecode.com/svn/trunk/naturalSort.js
388 function naturalSort (a, b) {
389 var re = /(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/gi,
390 sre = /(^[ ]*|[ ]*$)/g,
391 dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,
392 hre = /^0x[0-9a-f]+$/i,
394 // convert all to strings and trim()
395 x = a.toString().replace(sre, '') || '',
396 y = b.toString().replace(sre, '') || '',
398 xN = x.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
399 yN = y.replace(re, '\0$1\0').replace(/\0$/,'').replace(/^\0/,'').split('\0'),
400 // numeric, hex or date detection
401 xD = parseInt(x.match(hre), 10) || (xN.length != 1 && x.match(dre) && Date.parse(x)),
402 yD = parseInt(y.match(hre), 10) || xD && y.match(dre) && Date.parse(y) || null;
403 // first try and sort Hex codes or Dates
405 if ( xD < yD ) return -1;
406 else if ( xD > yD ) return 1;
407 // natural sorting through split numeric strings and default strings
408 for(var cLoc=0, numS=Math.max(xN.length, yN.length); cLoc < numS; cLoc++) {
409 // find floats not starting with '0', string or 0 if not defined (Clint Priest)
410 var oFxNcL = !(xN[cLoc] || '').match(ore) && parseFloat(xN[cLoc]) || xN[cLoc] || 0;
411 var oFyNcL = !(yN[cLoc] || '').match(ore) && parseFloat(yN[cLoc]) || yN[cLoc] || 0;
412 // handle numeric vs string comparison - number < string - (Kyle Adams)
413 if (isNaN(oFxNcL) !== isNaN(oFyNcL)) return (isNaN(oFxNcL)) ? 1 : -1;
414 // rely on string comparison if different types - i.e. '02' < 2 != '02' < '2'
415 else if (typeof oFxNcL !== typeof oFyNcL) {
419 if (oFxNcL < oFyNcL) return -1;
420 if (oFxNcL > oFyNcL) return 1;
425 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
426 "natural-asc": function ( a, b ) {
427 return naturalSort(a,b);
430 "natural-desc": function ( a, b ) {
431 return naturalSort(a,b) * -1;
437 /* Plugin to allow sorting on data stored in a span's title attribute
439 * Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td>
441 * In DataTables config:
443 * { "sType": "title-string" },
445 * http://datatables.net/plug-ins/sorting#hidden_title_string
447 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
448 "title-string-pre": function ( a ) {
449 return a.match(/title="(.*?)"/)[1].toLowerCase();
452 "title-string-asc": function ( a, b ) {
453 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
456 "title-string-desc": function ( a, b ) {
457 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
461 /* Plugin to allow sorting on numeric data stored in a span's title attribute
463 * Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]">
464 * [% formatted currency %]
467 * In DataTables config:
469 * { "sType": "title-numeric" },
471 * http://datatables.net/plug-ins/sorting#hidden_title
473 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
474 "title-numeric-pre": function ( a ) {
475 var x = a.match(/title="*(-?[0-9\.]+)/)[1];
476 return parseFloat( x );
479 "title-numeric-asc": function ( a, b ) {
480 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
483 "title-numeric-desc": function ( a, b ) {
484 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
490 /* Plugin to allow text sorting to ignore articles
492 * In DataTables config:
494 * { "sType": "anti-the" },
496 * Based on the plugin found here:
497 * http://datatables.net/plug-ins/sorting#anti_the
498 * Modified to exclude HTML tags from sorting
499 * Extended to accept a string of space-separated articles
500 * from a configuration file (in English, "a," "an," and "the")
503 if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){
504 var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" ");
506 for(i=0;i<articles.length;i++){
507 rpattern += "^" + articles[i] + " ";
508 if(i < articles.length - 1){ rpattern += "|"; }
510 var re = new RegExp(rpattern, "i");
513 jQuery.extend( jQuery.fn.dataTableExt.oSort, {
514 "anti-the-pre": function ( a ) {
515 var x = String(a).replace( /<[\s\S]*?>/g, "" );
517 var z = y.replace(re, "").toLowerCase();
521 "anti-the-asc": function ( a, b ) {
522 return ((a < b) ? -1 : ((a > b) ? 1 : 0));
525 "anti-the-desc": function ( a, b ) {
526 return ((a < b) ? 1 : ((a > b) ? -1 : 0));
532 // Remove string between NSB NSB characters
533 $.fn.dataTableExt.oSort['nsb-nse-asc'] = function(a,b) {
534 var pattern = new RegExp("\x88.*\x89");
535 a = a.replace(pattern, "");
536 b = b.replace(pattern, "");
537 return (a > b) ? 1 : ((a < b) ? -1 : 0);
539 $.fn.dataTableExt.oSort['nsb-nse-desc'] = function(a,b) {
540 var pattern = new RegExp("\x88.*\x89");
541 a = a.replace(pattern, "");
542 b = b.replace(pattern, "");
543 return (b > a) ? 1 : ((b < a) ? -1 : 0);
546 /* Define two custom functions (asc and desc) for basket callnumber sorting */
547 jQuery.fn.dataTableExt.oSort['callnumbers-asc'] = function(x,y) {
548 var x_array = x.split("<div>");
549 var y_array = y.split("<div>");
551 /* Pop the first elements, they are empty strings */
555 x_array = jQuery.map( x_array, function( a ) {
556 return parse_callnumber( a );
558 y_array = jQuery.map( y_array, function( a ) {
559 return parse_callnumber( a );
568 if ( !x ) { x = ""; }
569 if ( !y ) { y = ""; }
571 return ((x < y) ? -1 : ((x > y) ? 1 : 0));
574 jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
575 var x_array = x.split("<div>");
576 var y_array = y.split("<div>");
578 /* Pop the first elements, they are empty strings */
582 x_array = jQuery.map( x_array, function( a ) {
583 return parse_callnumber( a );
585 y_array = jQuery.map( y_array, function( a ) {
586 return parse_callnumber( a );
595 if ( !x ) { x = ""; }
596 if ( !y ) { y = ""; }
598 return ((x < y) ? 1 : ((x > y) ? -1 : 0));
601 function parse_callnumber ( html ) {
602 var array = html.split('<span class="callnumber">');
604 array = array[1].split('</span>');