-
Notifications
You must be signed in to change notification settings - Fork 917
/
Copy pathexport_buttons.blade.php
154 lines (149 loc) · 7.13 KB
/
export_buttons.blade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@if ($crud->exportButtons())
@basset('https://cdn.datatables.net/buttons/1.5.6/js/dataTables.buttons.min.js')
@basset('https://cdn.datatables.net/buttons/1.5.6/js/buttons.bootstrap4.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.18/pdfmake.min.js')
@basset('https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.18/vfs_fonts.js')
@basset('https://cdn.datatables.net/buttons/1.5.6/js/buttons.html5.min.js')
@basset('https://cdn.datatables.net/buttons/1.5.6/js/buttons.print.min.js')
@basset('https://cdn.datatables.net/buttons/1.5.6/js/buttons.colVis.min.js')
<script>
let dataTablesExportStrip = text => {
if ( typeof text !== 'string' ) {
return text;
}
return text
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
.replace(/<!\-\-.*?\-\->/g, '')
.replace(/<[^>]*>/g, '')
.replace(/^\s+|\s+$/g, '')
.replace(/\s+([,.;:!\?])/g, '$1')
.replace(/\s+/g, ' ')
.replace(/[\n|\r]/g, ' ');
};
let dataTablesExportFormat = {
body: (data, row, column, node) =>
node.querySelector('input[type*="text"]')?.value ??
node.querySelector('input[type*="checkbox"]:not(.crud_bulk_actions_line_checkbox)')?.checked ??
node.querySelector('select')?.selectedOptions[0]?.value ??
dataTablesExportStrip(data),
};
window.crud.dataTableConfiguration.buttons = [
@if($crud->get('list.showExportButton'))
{
extend: 'collection',
text: '<i class="la la-download"></i> {{ trans('backpack::crud.export.export') }}',
dropup: true,
buttons: [
{
name: 'copyHtml5',
extend: 'copyHtml5',
exportOptions: {
columns: function ( idx, data, node ) {
var $column = crud.table.column( idx );
return ($column.visible() && $(node).attr('data-visible-in-export') != 'false') || $(node).attr('data-force-export') == 'true';
},
format: dataTablesExportFormat,
},
action: function(e, dt, button, config) {
crud.responsiveToggle(dt);
$.fn.DataTable.ext.buttons.copyHtml5.action.call(this, e, dt, button, config);
crud.responsiveToggle(dt);
}
},
{
name: 'excelHtml5',
extend: 'excelHtml5',
exportOptions: {
columns: function ( idx, data, node ) {
var $column = crud.table.column( idx );
return ($column.visible() && $(node).attr('data-visible-in-export') != 'false') || $(node).attr('data-force-export') == 'true';
},
format: dataTablesExportFormat,
},
action: function(e, dt, button, config) {
crud.responsiveToggle(dt);
$.fn.DataTable.ext.buttons.excelHtml5.action.call(this, e, dt, button, config);
crud.responsiveToggle(dt);
}
},
{
name: 'csvHtml5',
extend: 'csvHtml5',
exportOptions: {
columns: function ( idx, data, node ) {
var $column = crud.table.column( idx );
return ($column.visible() && $(node).attr('data-visible-in-export') != 'false') || $(node).attr('data-force-export') == 'true';
},
format: dataTablesExportFormat,
},
action: function(e, dt, button, config) {
crud.responsiveToggle(dt);
$.fn.DataTable.ext.buttons.csvHtml5.action.call(this, e, dt, button, config);
crud.responsiveToggle(dt);
}
},
{
name: 'pdfHtml5',
extend: 'pdfHtml5',
exportOptions: {
columns: function ( idx, data, node ) {
var $column = crud.table.column( idx );
return ($column.visible() && $(node).attr('data-visible-in-export') != 'false') || $(node).attr('data-force-export') == 'true';
},
format: dataTablesExportFormat,
},
orientation: 'landscape',
action: function(e, dt, button, config) {
crud.responsiveToggle(dt);
$.fn.DataTable.ext.buttons.pdfHtml5.action.call(this, e, dt, button, config);
crud.responsiveToggle(dt);
}
},
{
name: 'print',
extend: 'print',
exportOptions: {
columns: function ( idx, data, node ) {
var $column = crud.table.column( idx );
return ($column.visible() && $(node).attr('data-visible-in-export') != 'false') || $(node).attr('data-force-export') == 'true';
},
format: dataTablesExportFormat,
},
action: function(e, dt, button, config) {
crud.responsiveToggle(dt);
$.fn.DataTable.ext.buttons.print.action.call(this, e, dt, button, config);
crud.responsiveToggle(dt);
}
}
]
}
@endif
@if($crud->get('list.showTableColumnPicker'))
,{
extend: 'colvis',
text: '<i class="la la-eye-slash"></i> {{ trans('backpack::crud.export.column_visibility') }}',
columns: function ( idx, data, node ) {
return $(node).attr('data-visible-in-table') == 'false' && $(node).attr('data-can-be-visible-in-table') == 'true';
},
dropup: true
}
@endif
];
// move the datatable buttons in the top-right corner and make them smaller
function moveExportButtonsToTopRight() {
crud.table.buttons().each(function(button) {
if (button.node.className.indexOf('buttons-columnVisibility') == -1 && button.node.nodeName=='BUTTON')
{
button.node.className = button.node.className + " btn-sm";
}
})
$(".dt-buttons").appendTo($('#datatable_button_stack' ));
$('.dt-buttons').addClass('d-xs-block')
.addClass('d-sm-inline-block')
.addClass('d-md-inline-block')
.addClass('d-lg-inline-block');
}
crud.addFunctionToDataTablesDrawEventQueue('moveExportButtonsToTopRight');
</script>
@endif