Commit 3abde1d5 authored by Kevin Yumang's avatar Kevin Yumang

SERV-2286 - datatable exporting buttons

parent f2311403
......@@ -47,10 +47,10 @@ function limitless_init_datatable() {
var counter = 0;
var sort = [];
var orderable = [];
$('#Datatable' + DatatableCounter).find('th').each(function () {
let tableHeaderElement = $(this);
console.log(tableHeaderElement);
// define sort
if (tableHeaderElement.attr('Sort') != undefined) {
......@@ -93,18 +93,24 @@ function limitless_init_datatable() {
var Complex = false;
}
if(elementTable.hasClass('downloadbuttons')){
// export buttons
let showExportButtons = elementTable.attr('exportable') != undefined && (elementTable.attr('exportable') == "true" || elementTable.attr('exportable') == true);
let exportButtons = ['copy', 'csv', 'excel', 'pdf', 'print'];
$(".dt-buttons").removeClass('hideBtn');
$(".dt-buttons").addClass('showBtn');
// Define the table control elements to appear on the page and in what order.
// https://datatables.net/reference/option/dom
let dom = showExportButtons ? 'Blfrtip' : 'lfrtip';
} else {
$(".dt-buttons").addClass('hideBtn');
}
// length menu
let lengthMenu = [
[10, 25, 50, 100, 500, -1],
['Standard (10)', 25, 50, 100, 500, "Alle"]
];
// activate datatable
$('#Datatable' + DatatableCounter).dataTable({
'dom': '<"c8tableTools01"Bf><"c8tableBody"t><"c8tableTools02"lipr>',
'dom': dom,
"fixedHeader": true,
'autoWidth': true,
'pageLength': parseInt(rows),
......@@ -113,33 +119,16 @@ function limitless_init_datatable() {
"searching": Complex,
"info": Complex,
"columnDefs": orderable,
"buttons": [
'csv', 'excel'
],
"buttons": exportButtons,
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/German.json"
},
"lengthMenu": [
[rows, 10, 25, 50, 100, 500, -1],
['Standard (' + rows + ')', 10, 25, 50, 100, 500, "Alle"]
],
"lengthMenu": lengthMenu,
"drawCallback": function (settings) {
var hasClass = $('table').hasClass('downloadbuttons');
if($('.buttons-excel').length > 0) {
$('.buttons-excel')[0].style.visibility = hasClass ? 'visible' : 'hidden';
}
if($('.buttons-csv').length > 0) {
$('.buttons-csv')[0].style.visibility = hasClass ? 'visible' : 'hidden';
}
// calculate height for animation
var height = $('#' + settings.sTableId).parents('.dataTables_wrapper').first().height() + 10;
// add classes to filter and select dropdown
$('.dataTables_filter input').addClass('DatatableSearch');
$('.dataTables_length label select').addClass('DatatableFilter');
......
/*!
Print button for Buttons and DataTables.
2016 SpryMedia Ltd - datatables.net/license
*/
(function(b){"function"===typeof define&&define.amd?define(["jquery","datatables.net","datatables.net-buttons"],function(d){return b(d,window,document)}):"object"===typeof exports?module.exports=function(d,h){d||(d=window);h&&h.fn.dataTable||(h=require("datatables.net")(d,h).$);h.fn.dataTable.Buttons||require("datatables.net-buttons")(d,h);return b(h,d,d.document)}:b(jQuery,window,document)})(function(b,d,h,y){var u=b.fn.dataTable,n=h.createElement("a"),v=function(a){n.href=a;a=n.host;-1===a.indexOf("/")&&
0!==n.pathname.indexOf("/")&&(a+="/");return n.protocol+"//"+a+n.pathname+n.search};u.ext.buttons.print={className:"buttons-print",text:function(a){return a.i18n("buttons.print","Print")},action:function(a,e,p,k){a=e.buttons.exportData(b.extend({decodeEntities:!1},k.exportOptions));p=e.buttons.exportInfo(k);var w=e.columns(k.exportOptions.columns).flatten().map(function(f){return e.settings()[0].aoColumns[e.column(f).index()].sClass}).toArray(),r=function(f,g){for(var x="<tr>",l=0,z=f.length;l<z;l++)x+=
"<"+g+" "+(w[l]?'class="'+w[l]+'"':"")+">"+(null===f[l]||f[l]===y?"":f[l])+"</"+g+">";return x+"</tr>"},m='<table class="'+e.table().node().className+'">';k.header&&(m+="<thead>"+r(a.header,"th")+"</thead>");m+="<tbody>";for(var t=0,A=a.body.length;t<A;t++)m+=r(a.body[t],"td");m+="</tbody>";k.footer&&a.footer&&(m+="<tfoot>"+r(a.footer,"th")+"</tfoot>");m+="</table>";var c=d.open("","");if(c){c.document.close();var q="<title>"+p.title+"</title>";b("style, link").each(function(){var f=q,g=b(this).clone()[0];
"link"===g.nodeName.toLowerCase()&&(g.href=v(g.href));q=f+g.outerHTML});try{c.document.head.innerHTML=q}catch(f){b(c.document.head).html(q)}c.document.body.innerHTML="<h1>"+p.title+"</h1><div>"+(p.messageTop||"")+"</div>"+m+"<div>"+(p.messageBottom||"")+"</div>";b(c.document.body).addClass("dt-print-view");b("img",c.document.body).each(function(f,g){g.setAttribute("src",v(g.getAttribute("src")))});k.customize&&k.customize(c,k,e);a=function(){k.autoPrint&&(c.print(),c.close())};navigator.userAgent.match(/Trident\/\d.\d/)?
a():c.setTimeout(a,1E3)}else e.buttons.info(e.i18n("buttons.printErrorTitle","Unable to open print view"),e.i18n("buttons.printErrorMsg","Please allow popups in your browser for this site to be able to view the print view."),5E3)},title:"*",messageTop:"*",messageBottom:"*",exportOptions:{},header:!0,footer:!1,autoPrint:!0,customize:null};return u.Buttons});
\ No newline at end of file
......@@ -42,30 +42,21 @@
{
$this->assetAllocation = [
'Limitless::DatatableStart' => [
'Attachments/jquery.dataTables.min.js',
'Attachments/jquery.dataTables.min.css',
'Attachments/exporting/buttons.dataTables.min.css',
'Attachments/exporting/dataTables.buttons.min.js',
'Attachments/exporting/jszip.min.js',
'Attachments/exporting/pdfmake.min.js',
'Attachments/exporting/vfs_fonts.js',
'Attachments/exporting/buttons.html5.min.js',
'Attachments/exporting/buttons.print.min.js',
'Attachments/datatables.init.js',
'Attachments/datatables.init.css',
'Attachments/jquery.datatables.js',
]
];
}
// this jquery datatables
// secure_url("/ceetrox/sidekick/resource/public/Webdesigns/design-limitless/Template/global_assets/js/demo_pages/datatables_basic.js"),
// secure_url("/ceetrox/sidekick/resource/public/Webdesigns/design-limitless/Template/global_assets/js/plugins/tables/datatables/datatables.min.js"),
// secure_url("/ceetrox/sidekick/resource/public/Webdesigns/design-limitless/Template/global_assets/js/plugins/forms/selects/select2.min.js"),
// NEXUS LIMITLESS
// 'Attachments/datatables.js',
// 'Attachments/jquery.datatables.js'
// 'Attachments/jquery.datatables.css',
// 'Attachments/exporting/buttons,print.min.js',
// 'Attachments/exporting/buttons.flash.min.js',
// 'Attachments/exporting/buttons.html5.min.js',
// 'Attachments/exporting/datatables.buttons.min.js',
// 'Attachments/exporting/jszip.min.js',
// 'Attachments/exporting/pdfmake.min.js',
// 'Attachments/exporting/vfs.fonts.js',
// 'datatable.css'
/*
|--------------------------------------------------------------------------------------------
......@@ -76,7 +67,8 @@
{
return View('Limitless::Datatable.Start')
->withExtra($parameters['extra'] ?? [])
->withRows($parameters['rows'] ?? null);
->withRows($parameters['rows'] ?? null)
->withExportable($parameters['exportable'] ?? null);
}
......
......@@ -7,7 +7,7 @@
@Limitless::CardStart(['title' => "Datatable", 'icon' => 'icon-table2'])
<p>A data container with rows and columns.</p>
@Limitless::DatatableStart([ 'extra' => ['class' => 'table table-striped']])
@Limitless::DatatableStart(['exportable' => 'true', 'extra' => ['class' => 'table table-striped']])
@Limitless::TableAutofillHeader([
['name' => 'Name'],
......@@ -65,7 +65,7 @@
@Limitless::CardStop
@Limitless::DatatableStart([ 'extra' => ['class' => 'table table-striped']])
@Limitless::DatatableStart([ 'extra' => ['class' => 'table table-striped'], 'exportable' => true ])
<thead>
<th Sortable=false> Name </th>
......
......@@ -11,5 +11,5 @@
@endforeach
@if($rows) rows='{{ $rows }}' @endif
@if($exportable) exportable='{{ $exportable }}' @endif
class="table LimitlessTable" hidden>
@if( !empty($data) )
<tbody>
@foreach($data as $tr)
<tr>
@foreach($tr as $td)
@if( @$td['secure'] === false)
<td> {!! $td['value'] !!} </td>
@else
<td> {{ $td['value'] }} </td>
@endif
@endforeach
</tr>
@endforeach
</tbody>
@endif
@if( !empty($data) )
<thead>
<tr>
@foreach($data as $th)
@if( @$th['secure'] === false)
<th> {!! $th['name'] !!} </th>
@else
<th> {{ $th['name'] }} </th>
@endif
@endforeach
</tr>
</thead>
@endif
......@@ -45,14 +45,6 @@
overflow-x: auto;
}
/*.DatatableFader {*/
/* opacity: 0;*/
/* overflow-y: hidden;*/
/*}*/
/*.LimitlessTable*/
/*{*/
/* display: none;*/
/*}*/
table.fixedHeader-floating{position:fixed !important;background-color:white}table.fixedHeader-floating.no-footer{border-bottom-width:0}table.fixedHeader-locked{position:absolute !important;background-color:white}@media print{table.fixedHeader-floating{display:none}}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment