|
Lines 1-49
Link Here
|
| 1 |
// These default options are for translation but can be used |
1 |
// These default options are for translation but can be used |
| 2 |
// for any other datatables settings |
2 |
// for any other datatables settings |
| 3 |
// MSG_DT_* variables comes from datatables.inc |
|
|
| 4 |
// To use it, write: |
3 |
// To use it, write: |
| 5 |
// $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, { |
4 |
// $("#table_id").dataTable($.extend(true, {}, dataTableDefaults, { |
| 6 |
// // other settings |
5 |
// // other settings |
| 7 |
// } ) ); |
6 |
// } ) ); |
| 8 |
var dataTablesDefaults = { |
7 |
var dataTablesDefaults = { |
| 9 |
"language": { |
8 |
"oLanguage": { |
| 10 |
"paginate": { |
9 |
"oPaginate": { |
| 11 |
"first" : window.MSG_DT_FIRST || "First", |
10 |
"sFirst" : __('First'), |
| 12 |
"last" : window.MSG_DT_LAST || "Last", |
11 |
"sLast" : __('Last'), |
| 13 |
"next" : window.MSG_DT_NEXT || "Next", |
12 |
"sNext" : __('Next'), |
| 14 |
"previous" : window.MSG_DT_PREVIOUS || "Previous" |
13 |
"sPrevious" : __('Previous'), |
| 15 |
}, |
14 |
}, |
| 16 |
"emptyTable" : window.MSG_DT_EMPTY_TABLE || "No data available in table", |
15 |
"sEmptyTable" : __('No data available in table'), |
| 17 |
"info" : window.MSG_DT_INFO || "Showing _START_ to _END_ of _TOTAL_ entries", |
16 |
"sInfo" : __('Showing _START_ to _END_ of _TOTAL_ entries'), |
| 18 |
"infoEmpty" : window.MSG_DT_INFO_EMPTY || "No entries to show", |
17 |
"sInfoEmpty" : __('No entries to show'), |
| 19 |
"infoFiltered" : window.MSG_DT_INFO_FILTERED || "(filtered from _MAX_ total entries)", |
18 |
"sInfoFiltered" : __('(filtered from _MAX_ total entries)'), |
| 20 |
"lengthMenu" : window.MSG_DT_LENGTH_MENU || "Show _MENU_ entries", |
19 |
"sLengthMenu" : __('Show _MENU_ entries'), |
| 21 |
"loadingRecords" : window.MSG_DT_LOADING_RECORDS || "Loading...", |
20 |
"sLoadingRecords" : __('Loading...'), |
| 22 |
"processing" : window.MSG_DT_PROCESSING || "Processing...", |
21 |
"sProcessing" : __('Processing...'), |
| 23 |
"search" : window.MSG_DT_SEARCH || "Search:", |
22 |
"sSearch" : __('Search:'), |
| 24 |
"zeroRecords" : window.MSG_DT_ZERO_RECORDS || "No matching records found" |
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 |
} |
| 25 |
}, |
32 |
}, |
| 26 |
// "sorting": [$(" - select row position of th -")], |
33 |
"dom": '<"top pager"<"table_entries"ilp><"table_controls"fB>>tr<"bottom pager"ip>', |
| 27 |
"dom": 't', |
34 |
"buttons": [{ |
| 28 |
"paginate": false, |
35 |
fade: 100, |
| 29 |
// "fnHeaderCallback": function() { |
36 |
className: "dt_button_clear_filter", |
| 30 |
// return $('th.sorting.nosort,th.sorting_desc.nosort,th.sorting_asc.nosort').removeClass("sorting sorting_desc sorting_asc").unbind("click"); |
37 |
titleAttr: __('Clear filter'), |
| 31 |
// } |
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 |
} |
| 32 |
}; |
66 |
}; |
| 33 |
|
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 |
|
| 34 |
/* Plugin to allow sorting on data stored in a span's title attribute |
288 |
/* Plugin to allow sorting on data stored in a span's title attribute |
| 35 |
* |
289 |
* |
| 36 |
* Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td> |
290 |
* Ex: <td><span title="[% ISO_date %]">[% formatted_date %]</span></td> |
| 37 |
* |
291 |
* |
| 38 |
* In DataTables config: |
292 |
* In DataTables config: |
| 39 |
* "columns": [ |
293 |
* "aoColumns": [ |
| 40 |
* { "type": "title-string" }, |
294 |
* { "sType": "title-string" }, |
| 41 |
* ] |
295 |
* ] |
| 42 |
* http://datatables.net/plug-ins/sorting#hidden_title_string |
296 |
* http://datatables.net/plug-ins/sorting#hidden_title_string |
| 43 |
*/ |
297 |
*/ |
| 44 |
jQuery.extend( jQuery.fn.dataTableExt.sort, { |
298 |
jQuery.extend( jQuery.fn.dataTableExt.oSort, { |
| 45 |
"title-string-pre": function ( a ) { |
299 |
"title-string-pre": function ( a ) { |
| 46 |
return a.match(/title="(.*?)"/)[1].toLowerCase(); |
300 |
var m = a.match(/title="(.*?)"/); |
|
|
301 |
if ( null !== m && m.length ) { |
| 302 |
return m[1].toLowerCase(); |
| 303 |
} |
| 304 |
return ""; |
| 47 |
}, |
305 |
}, |
| 48 |
|
306 |
|
| 49 |
"title-string-asc": function ( a, b ) { |
307 |
"title-string-asc": function ( a, b ) { |
|
Lines 55-71
jQuery.extend( jQuery.fn.dataTableExt.sort, {
Link Here
|
| 55 |
} |
313 |
} |
| 56 |
} ); |
314 |
} ); |
| 57 |
|
315 |
|
| 58 |
/* Plugin to allow sorting numerically on data stored in a span's title attribute |
316 |
/* Plugin to allow sorting on numeric data stored in a span's title attribute |
| 59 |
* |
317 |
* |
| 60 |
* Ex: <td><span title="[% total %]">Total: [% total %]</span></td> |
318 |
* Ex: <td><span title="[% decimal_number_that_JS_parseFloat_accepts %]"> |
|
|
319 |
* [% formatted currency %] |
| 320 |
* </span></td> |
| 61 |
* |
321 |
* |
| 62 |
* In DataTables config: |
322 |
* In DataTables config: |
| 63 |
* "columns": [ |
323 |
* "aoColumns": [ |
| 64 |
* { "type": "title-numeric" } |
324 |
* { "sType": "title-numeric" }, |
| 65 |
* ] |
325 |
* ] |
| 66 |
* http://legacy.datatables.net/plug-ins/sorting#hidden_title |
326 |
* http://datatables.net/plug-ins/sorting#hidden_title |
| 67 |
*/ |
327 |
*/ |
| 68 |
jQuery.extend( jQuery.fn.dataTableExt.sort, { |
328 |
jQuery.extend( jQuery.fn.dataTableExt.oSort, { |
| 69 |
"title-numeric-pre": function ( a ) { |
329 |
"title-numeric-pre": function ( a ) { |
| 70 |
var x = a.match(/title="*(-?[0-9\.]+)/)[1]; |
330 |
var x = a.match(/title="*(-?[0-9\.]+)/)[1]; |
| 71 |
return parseFloat( x ); |
331 |
return parseFloat( x ); |
|
Lines 85-92
jQuery.extend( jQuery.fn.dataTableExt.sort, {
Link Here
|
| 85 |
/* Plugin to allow text sorting to ignore articles |
345 |
/* Plugin to allow text sorting to ignore articles |
| 86 |
* |
346 |
* |
| 87 |
* In DataTables config: |
347 |
* In DataTables config: |
| 88 |
* "columns": [ |
348 |
* "aoColumns": [ |
| 89 |
* { "type": "anti-the" }, |
349 |
* { "sType": "anti-the" }, |
| 90 |
* ] |
350 |
* ] |
| 91 |
* Based on the plugin found here: |
351 |
* Based on the plugin found here: |
| 92 |
* http://datatables.net/plug-ins/sorting#anti_the |
352 |
* http://datatables.net/plug-ins/sorting#anti_the |
|
Lines 95-102
jQuery.extend( jQuery.fn.dataTableExt.sort, {
Link Here
|
| 95 |
* from a configuration file (in English, "a," "an," and "the") |
355 |
* from a configuration file (in English, "a," "an," and "the") |
| 96 |
*/ |
356 |
*/ |
| 97 |
|
357 |
|
| 98 |
if(CONFIG_EXCLUDE_ARTICLES_FROM_SORT){ |
358 |
var config_exclude_articles_from_sort = __('a an the'); |
| 99 |
var articles = CONFIG_EXCLUDE_ARTICLES_FROM_SORT.split(" "); |
359 |
if (config_exclude_articles_from_sort){ |
|
|
360 |
var articles = config_exclude_articles_from_sort.split(" "); |
| 100 |
var rpattern = ""; |
361 |
var rpattern = ""; |
| 101 |
for(i=0;i<articles.length;i++){ |
362 |
for(i=0;i<articles.length;i++){ |
| 102 |
rpattern += "^" + articles[i] + " "; |
363 |
rpattern += "^" + articles[i] + " "; |
|
Lines 105-111
jQuery.extend( jQuery.fn.dataTableExt.sort, {
Link Here
|
| 105 |
var re = new RegExp(rpattern, "i"); |
366 |
var re = new RegExp(rpattern, "i"); |
| 106 |
} |
367 |
} |
| 107 |
|
368 |
|
| 108 |
jQuery.extend( jQuery.fn.dataTableExt.sort, { |
369 |
jQuery.extend( jQuery.fn.dataTableExt.oSort, { |
| 109 |
"anti-the-pre": function ( a ) { |
370 |
"anti-the-pre": function ( a ) { |
| 110 |
var x = String(a).replace( /<[\s\S]*?>/g, "" ); |
371 |
var x = String(a).replace( /<[\s\S]*?>/g, "" ); |
| 111 |
var y = x.trim(); |
372 |
var y = x.trim(); |
|
Lines 124-136
jQuery.extend( jQuery.fn.dataTableExt.sort, {
Link Here
|
| 124 |
|
385 |
|
| 125 |
}()); |
386 |
}()); |
| 126 |
|
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 |
|
| 127 |
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { |
506 |
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) { |
| 128 |
console.warn(message); |
507 |
console.warn(message); |
| 129 |
}; |
508 |
}; |
| 130 |
|
509 |
|
| 131 |
(function($) { |
510 |
(function($) { |
| 132 |
|
511 |
|
| 133 |
$.fn.api = function(options) { |
512 |
$.fn.api = function(options, columns_settings, add_filters) { |
| 134 |
var settings = null; |
513 |
var settings = null; |
| 135 |
if(options) { |
514 |
if(options) { |
| 136 |
settings = $.extend(true, {}, dataTablesDefaults, { |
515 |
settings = $.extend(true, {}, dataTablesDefaults, { |
|
Lines 138-143
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
Link Here
|
| 138 |
"paging": true, |
517 |
"paging": true, |
| 139 |
'serverSide': true, |
518 |
'serverSide': true, |
| 140 |
'searching': true, |
519 |
'searching': true, |
|
|
520 |
'processing': true, |
| 521 |
'language': { |
| 522 |
'emptyTable': (options.emptyTable) ? options.emptyTable : "No data available in table" |
| 523 |
}, |
| 141 |
'pagingType': 'full', |
524 |
'pagingType': 'full', |
| 142 |
'ajax': { |
525 |
'ajax': { |
| 143 |
'type': 'GET', |
526 |
'type': 'GET', |
|
Lines 210-216
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
Link Here
|
| 210 |
} |
593 |
} |
| 211 |
}, options); |
594 |
}, options); |
| 212 |
} |
595 |
} |
|
|
596 |
|
| 597 |
var counter = 0; |
| 598 |
var hidden_ids = []; |
| 599 |
var included_ids = []; |
| 600 |
|
| 601 |
$(columns_settings).each( function() { |
| 602 |
var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' ); |
| 603 |
var used_id = settings.bKohaColumnsUseNames ? named_id : counter; |
| 604 |
if ( used_id == -1 ) return; |
| 605 |
|
| 606 |
if ( this['is_hidden'] == "1" ) { |
| 607 |
hidden_ids.push( used_id ); |
| 608 |
} |
| 609 |
if ( this['cannot_be_toggled'] == "0" ) { |
| 610 |
included_ids.push( used_id ); |
| 611 |
} |
| 612 |
counter++; |
| 613 |
}); |
| 614 |
|
| 615 |
var exportColumns = ":visible:not(.noExport)"; |
| 616 |
if( settings.hasOwnProperty("exportColumns") ){ |
| 617 |
// A custom buttons configuration has been passed from the page |
| 618 |
exportColumns = settings["exportColumns"]; |
| 619 |
} |
| 620 |
|
| 621 |
var export_format = { |
| 622 |
body: function ( data, row, column, node ) { |
| 623 |
var newnode = $(node); |
| 624 |
|
| 625 |
if ( newnode.find(".noExport").length > 0 ) { |
| 626 |
newnode = newnode.clone(); |
| 627 |
newnode.find(".noExport").remove(); |
| 628 |
} |
| 629 |
|
| 630 |
return newnode.text().replace( /\n/g, ' ' ).trim(); |
| 631 |
} |
| 632 |
} |
| 633 |
|
| 634 |
var export_buttons = [ |
| 635 |
{ |
| 636 |
extend: 'excelHtml5', |
| 637 |
text: _("Excel"), |
| 638 |
exportOptions: { |
| 639 |
columns: exportColumns, |
| 640 |
format: export_format |
| 641 |
}, |
| 642 |
}, |
| 643 |
{ |
| 644 |
extend: 'csvHtml5', |
| 645 |
text: _("CSV"), |
| 646 |
exportOptions: { |
| 647 |
columns: exportColumns, |
| 648 |
format: export_format |
| 649 |
}, |
| 650 |
}, |
| 651 |
{ |
| 652 |
extend: 'copyHtml5', |
| 653 |
text: _("Copy"), |
| 654 |
exportOptions: { |
| 655 |
columns: exportColumns, |
| 656 |
format: export_format |
| 657 |
}, |
| 658 |
}, |
| 659 |
{ |
| 660 |
extend: 'print', |
| 661 |
text: _("Print"), |
| 662 |
exportOptions: { |
| 663 |
columns: exportColumns, |
| 664 |
format: export_format |
| 665 |
}, |
| 666 |
} |
| 667 |
]; |
| 668 |
|
| 669 |
settings[ "buttons" ] = [ |
| 670 |
{ |
| 671 |
fade: 100, |
| 672 |
className: "dt_button_clear_filter", |
| 673 |
titleAttr: _("Clear filter"), |
| 674 |
enabled: false, |
| 675 |
text: '<i class="fa fa-lg fa-remove"></i> <span class="dt-button-text">' + _("Clear filter") + '</span>', |
| 676 |
action: function ( e, dt, node, config ) { |
| 677 |
dt.search( "" ).draw("page"); |
| 678 |
node.addClass("disabled"); |
| 679 |
} |
| 680 |
} |
| 681 |
]; |
| 682 |
|
| 683 |
if( included_ids.length > 0 ){ |
| 684 |
settings[ "buttons" ].push( |
| 685 |
{ |
| 686 |
extend: 'colvis', |
| 687 |
fade: 100, |
| 688 |
columns: included_ids, |
| 689 |
className: "columns_controls", |
| 690 |
titleAttr: _("Columns settings"), |
| 691 |
text: '<i class="fa fa-lg fa-gear"></i> <span class="dt-button-text">' + _("Columns") + '</span>', |
| 692 |
exportOptions: { |
| 693 |
columns: exportColumns |
| 694 |
} |
| 695 |
} |
| 696 |
); |
| 697 |
} |
| 698 |
|
| 699 |
settings[ "buttons" ].push( |
| 700 |
{ |
| 701 |
extend: 'collection', |
| 702 |
autoClose: true, |
| 703 |
fade: 100, |
| 704 |
className: "export_controls", |
| 705 |
titleAttr: _("Export or print"), |
| 706 |
text: '<i class="fa fa-lg fa-download"></i> <span class="dt-button-text">' + _("Export") + '</span>', |
| 707 |
buttons: export_buttons |
| 708 |
} |
| 709 |
); |
| 710 |
|
| 711 |
if ( add_filters ) { |
| 712 |
// Duplicate the table header row for columnFilter |
| 713 |
thead_row = this.find('thead tr'); |
| 714 |
clone = thead_row.clone().addClass('filters_row'); |
| 715 |
clone.find("th.NoSort").html(''); |
| 716 |
thead_row.before(clone); |
| 717 |
} |
| 718 |
|
| 719 |
$(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip(); |
| 720 |
|
| 213 |
return $(this).dataTable(settings); |
721 |
return $(this).dataTable(settings); |
| 214 |
}; |
722 |
}; |
| 215 |
|
723 |
|
| 216 |
})(jQuery); |
724 |
})(jQuery); |
| 217 |
- |
|
|