");
+
+ /* Pop the first elements, they are empty strings */
+ x_array.shift();
+ y_array.shift();
+
+ x_array = jQuery.map( x_array, function( a ) {
+ return parse_callnumber( a );
+ });
+ y_array = jQuery.map( y_array, function( a ) {
+ return parse_callnumber( a );
+ });
+
+ x_array.sort();
+ y_array.sort();
+
+ x = x_array.shift();
+ y = y_array.shift();
+
+ if ( !x ) { x = ""; }
+ if ( !y ) { y = ""; }
+
+ return ((x < y) ? -1 : ((x > y) ? 1 : 0));
+};
+
+jQuery.fn.dataTableExt.oSort['callnumbers-desc'] = function(x,y) {
+ var x_array = x.split("
");
+ var y_array = y.split("
");
+
+ /* Pop the first elements, they are empty strings */
+ x_array.shift();
+ y_array.shift();
+
+ x_array = jQuery.map( x_array, function( a ) {
+ return parse_callnumber( a );
+ });
+ y_array = jQuery.map( y_array, function( a ) {
+ return parse_callnumber( a );
+ });
+
+ x_array.sort();
+ y_array.sort();
+
+ x = x_array.pop();
+ y = y_array.pop();
+
+ if ( !x ) { x = ""; }
+ if ( !y ) { y = ""; }
+
+ return ((x < y) ? 1 : ((x > y) ? -1 : 0));
+};
+
+function parse_callnumber ( html ) {
+ var array = html.split('');
+ if ( array[1] ) {
+ array = array[1].split('');
+ return array[0];
+ } else {
+ return "";
+ }
+}
+
+// see http://www.datatables.net/examples/advanced_init/footer_callback.html
+function footer_column_sum( api, column_numbers ) {
+ // Remove the formatting to get integer data for summation
+ var intVal = function ( i ) {
+ if ( typeof i === 'number' ) {
+ if ( isNaN(i) ) return 0;
+ return i;
+ } else if ( typeof i === 'string' ) {
+ var value = i.replace(/[a-zA-Z ,.]/g, '')*1;
+ if ( isNaN(value) ) return 0;
+ return value;
+ }
+ return 0;
+ };
+
+
+ for ( var indice = 0 ; indice < column_numbers.length ; indice++ ) {
+ var column_number = column_numbers[indice];
+
+ var total = 0;
+ var cells = api.column( column_number, { page: 'current' } ).nodes().to$().find("span.total_amount");
+ $(cells).each(function(){
+ total += intVal( $(this).html() );
+ });
+ total /= 100; // Hard-coded decimal precision
+
+ // Update footer
+ $( api.column( column_number ).footer() ).html(total.format_price());
+ };
+}
+
+function filterDataTable( table, column, term ){
+ if( column ){
+ table.column( column ).search( term ).draw("page");
+ } else {
+ table.search( term ).draw("page");
+ }
+}
+
jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
console.warn(message);
};
(function($) {
- $.fn.api = function(options) {
+ $.fn.api = function(options, columns_settings, add_filters) {
var settings = null;
if(options) {
settings = $.extend(true, {}, dataTablesDefaults, {
@@ -138,6 +517,10 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
"paging": true,
'serverSide': true,
'searching': true,
+ 'processing': true,
+ 'language': {
+ 'emptyTable': (options.emptyTable) ? options.emptyTable : "No data available in table"
+ },
'pagingType': 'full',
'ajax': {
'type': 'GET',
@@ -210,7 +593,132 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
}
}, options);
}
+
+ var counter = 0;
+ var hidden_ids = [];
+ var included_ids = [];
+
+ $(columns_settings).each( function() {
+ var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', this ).index( 'th' );
+ var used_id = settings.bKohaColumnsUseNames ? named_id : counter;
+ if ( used_id == -1 ) return;
+
+ if ( this['is_hidden'] == "1" ) {
+ hidden_ids.push( used_id );
+ }
+ if ( this['cannot_be_toggled'] == "0" ) {
+ included_ids.push( used_id );
+ }
+ counter++;
+ });
+
+ var exportColumns = ":visible:not(.noExport)";
+ if( settings.hasOwnProperty("exportColumns") ){
+ // A custom buttons configuration has been passed from the page
+ exportColumns = settings["exportColumns"];
+ }
+
+ var export_format = {
+ body: function ( data, row, column, node ) {
+ var newnode = $(node);
+
+ if ( newnode.find(".noExport").length > 0 ) {
+ newnode = newnode.clone();
+ newnode.find(".noExport").remove();
+ }
+
+ return newnode.text().replace( /\n/g, ' ' ).trim();
+ }
+ }
+
+ var export_buttons = [
+ {
+ extend: 'excelHtml5',
+ text: _("Excel"),
+ exportOptions: {
+ columns: exportColumns,
+ format: export_format
+ },
+ },
+ {
+ extend: 'csvHtml5',
+ text: _("CSV"),
+ exportOptions: {
+ columns: exportColumns,
+ format: export_format
+ },
+ },
+ {
+ extend: 'copyHtml5',
+ text: _("Copy"),
+ exportOptions: {
+ columns: exportColumns,
+ format: export_format
+ },
+ },
+ {
+ extend: 'print',
+ text: _("Print"),
+ exportOptions: {
+ columns: exportColumns,
+ format: export_format
+ },
+ }
+ ];
+
+ settings[ "buttons" ] = [
+ {
+ fade: 100,
+ className: "dt_button_clear_filter",
+ titleAttr: _("Clear filter"),
+ enabled: false,
+ text: ' ' + _("Clear filter") + '',
+ action: function ( e, dt, node, config ) {
+ dt.search( "" ).draw("page");
+ node.addClass("disabled");
+ }
+ }
+ ];
+
+ if( included_ids.length > 0 ){
+ settings[ "buttons" ].push(
+ {
+ extend: 'colvis',
+ fade: 100,
+ columns: included_ids,
+ className: "columns_controls",
+ titleAttr: _("Columns settings"),
+ text: ' ' + _("Columns") + '',
+ exportOptions: {
+ columns: exportColumns
+ }
+ }
+ );
+ }
+
+ settings[ "buttons" ].push(
+ {
+ extend: 'collection',
+ autoClose: true,
+ fade: 100,
+ className: "export_controls",
+ titleAttr: _("Export or print"),
+ text: ' ' + _("Export") + '',
+ buttons: export_buttons
+ }
+ );
+
+ if ( add_filters ) {
+ // Duplicate the table header row for columnFilter
+ thead_row = this.find('thead tr');
+ clone = thead_row.clone().addClass('filters_row');
+ clone.find("th.NoSort").html('');
+ thead_row.before(clone);
+ }
+
+ $(".dt_button_clear_filter, .columns_controls, .export_controls").tooltip();
+
return $(this).dataTable(settings);
};
-})(jQuery);
+})(jQuery);
--