Owen Leonard
ba1f33e6ae
This patch changes the default DataTables configuration provided by the columns settings include file. It consolidates DataTables buttons into to menus: One for column configuration and one for export options. This change would not affect tables which aren't set up for column configuration. To test, apply the patch and view a page with columns configuration. Example: Tools -> Notices & slips - Confirm that the buttons appear as expected. - Confirm that each button menu performs its task correctly (column visiblity, export, print). - Test other pages with columns configuration. For instance: Acquisitions order search, Currencies administration, Holds queue Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Jose-Mario Monteiro-Santos <jose-mario.monteiro-santos@inLibro.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
107 lines
2.8 KiB
PHP
107 lines
2.8 KiB
PHP
[% USE ColumnsSettings %]
|
|
|
|
<script>
|
|
function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
|
|
var counter = 0;
|
|
var hidden_ids = [];
|
|
var included_ids = [];
|
|
var selector = '#' + id_selector;
|
|
|
|
$(columns_settings).each( function() {
|
|
var named_id = $( 'thead th[data-colname="' + this.columnname + '"]', selector ).index( 'th' );
|
|
var used_id = dt_parameters.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";
|
|
if( dt_parameters.hasOwnProperty("exportColumns") ){
|
|
// A custom buttons configuration has been passed from the page
|
|
exportColumns = dt_parameters["exportColumns"];
|
|
}
|
|
|
|
var export_buttons = [
|
|
{
|
|
extend: 'excelHtml5',
|
|
text: _("Excel"),
|
|
exportOptions: {
|
|
columns: exportColumns
|
|
},
|
|
},
|
|
{
|
|
extend: 'csvHtml5',
|
|
text: _("CSV"),
|
|
exportOptions: {
|
|
columns: exportColumns
|
|
},
|
|
},
|
|
{
|
|
extend: 'copyHtml5',
|
|
text: _("Copy"),
|
|
exportOptions: {
|
|
columns: exportColumns
|
|
},
|
|
},
|
|
{
|
|
extend: 'print',
|
|
text: _("Print"),
|
|
exportOptions: {
|
|
columns: exportColumns
|
|
},
|
|
}
|
|
];
|
|
|
|
dt_parameters[ "buttons" ] = [
|
|
{
|
|
extend: 'colvis',
|
|
fade: 100,
|
|
columns: included_ids,
|
|
text: '<i class="fa fa-lg fa-gear"></i>',
|
|
exportOptions: {
|
|
columns: exportColumns
|
|
},
|
|
},
|
|
{
|
|
extend: 'collection',
|
|
fade: 100,
|
|
text: '<i class="fa fa-lg fa-download"></i>',
|
|
buttons: export_buttons
|
|
}
|
|
|
|
];
|
|
|
|
var table = $(selector);
|
|
if ( add_filters ) {
|
|
// Duplicate the table header row for columnFilter
|
|
thead_row = table.find('thead tr');
|
|
clone = thead_row.clone().addClass('filters_row');
|
|
clone.find("th.NoSort").html('');
|
|
thead_row.before(clone);
|
|
}
|
|
|
|
table.dataTable($.extend(true, {}, dataTablesDefaults, dt_parameters));
|
|
|
|
$(hidden_ids).each(function(index, value) {
|
|
table.fnSetColumnVis( value, false );
|
|
});
|
|
|
|
if ( add_filters ) {
|
|
// show a link to activate filtering
|
|
link = $('<a>')
|
|
.attr('href', '#')
|
|
.attr('id', id_selector + '_activate_filters');
|
|
$("." + id_selector + "_table_controls").prepend(link);
|
|
deactivate_filters(id_selector);
|
|
}
|
|
|
|
return table;
|
|
}
|
|
|
|
</script>
|