-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-btn-pop-up.html
More file actions
177 lines (164 loc) · 5.76 KB
/
Copy pathexport-btn-pop-up.html
File metadata and controls
177 lines (164 loc) · 5.76 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DataTables Export Buttons</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.13.5/css/jquery.dataTables.min.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"
integrity="sha512-XMVd28F1oH/O71fzwBnV7HucLxVwtxf26XV8P4wPk26EDxuGZ91N8bsOttmnomcCD3CS5ZMRL50H0GgOHvegtg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.72/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.72/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.print.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<style>
.dataTables_wrapper .dataTables_filter {
float: right; /* Or left, depending on what you want */
text-align: right;
}
.custom-export-container {
display: flex;
justify-content: space-between;
}
.export-button-container {
text-align: right;
}
.popup-export {
display: none;
position: absolute;
background-color: #fff;
box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2);
padding: 10px 0;
z-index: 1;
border-radius: 5px;
margin-top: 5px;
}
.custom-export-button {
display: flex;
align-items: center;
justify-content: start;
white-space: nowrap;
padding: 10px 20px;
text-align: left;
cursor: pointer;
border: none;
background: none;
width: auto;
color: #333;
text-decoration: none;
}
.custom-export-button:hover {
background-color: #f3f3f3;
}
.custom-export-button i {
margin-right: 5px;
}
.custom-export-button .fa-file-csv {
color: #4CAF50; /* Green */
}
.custom-export-button .fa-file-excel {
color: #207245; /* Darker Green */
}
.custom-export-button .fa-file-pdf {
color: #D93025; /* Red */
}
</style>
<body>
<div class="custom-export-container">
<div class="length-change-container">
<!-- Placeholder for length changing input -->
</div>
<div class="export-button-container">
<button id="exportButton">Export <i class="fas fa-download"></i></button>
</div>
</div>
<div class="popup-export" id="exportOptions"></div>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td>System Architect</td>
<td>Edinburgh</td>
<td>61</td>
<td>2011/04/25</td>
<td>$320,800</td>
</tr>
<tr>
<td>Garrett Winters</td>
<td>Accountant</td>
<td>Tokyo</td>
<td>63</td>
<td>2011/07/25</td>
<td>$170,750</td>
</tr>
<!-- More rows -->
</tbody>
</table>
<script>
$(document).ready(function() {
var table = $('#example').DataTable({
dom: '<"custom-export-container"f>rtip', // Customize the dom; f - filtering input (search)
"searching": false, // Disable the search box
buttons: [
{
extend: 'csv',
text: '<i class="fas fa-file-csv"></i> CSV',
titleAttr: 'Export to CSV',
className: 'custom-export-button'
},
{
extend: 'excel',
text: '<i class="fas fa-file-excel"></i> Excel',
titleAttr: 'Export to Excel',
className: 'custom-export-button'
},
{
extend: 'pdf',
text: '<i class="fas fa-file-pdf"></i> PDF',
titleAttr: 'Export to PDF',
className: 'custom-export-button'
}
]
});
table.buttons().container().appendTo($('#exportOptions'));
// Place the Export button next to the DataTable search box
$('#exportButton').insertAfter('div.dataTables_filter label');
$('#exportButton').on('click', function() {
var exportBtnOffset = $(this).offset();
var exportBtnHeight = $(this).outerHeight();
$('#exportOptions').css({
'top': exportBtnOffset.top + exportBtnHeight,
'left': exportBtnOffset.left,
'position': 'absolute'
}).toggle();
});
// Hide the export options if clicking outside
$(document).on('click', function(e) {
if (!$(e.target).closest('#exportButton, .dt-button').length) {
$('#exportOptions').hide();
}
});
});
</script>
</body>
</html>