Met dataTables csv opslaan.
Code (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
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
$('#dt_startpage_links,#dt_blog_content_links,#dt_blog_sidebar_links,#dt_startpage_articles,#dt_blog-sold,#dt_link-sold').dataTable( {
scrollX: true,
processing: true,
serverSide: true,
ajax: {
url: '<?=HTML_ROOT?>inc/saveAjax.php',
type: 'GET'
},
dom: 'Bfrtip',
buttons: [
{
extend: 'excelHtml5',
text:'Excel',
className: 'excelbtn',
filename: 'Account_details',
title: 'Account Details',
titleAttr: 'Excel',
exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
}, {
extend: 'pdfHtml5',
text:'PSF',
className: 'pdfbtn',
filename: 'Account_details',
title: 'Account Details',
titleAttr: 'PDF',
exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
}, {
extend: 'csv',
text:'CSV',
className: 'csv',
filename: 'Account_details',
title: 'Account Details',
titleAttr: 'Reports',
exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
}
],
columnDefs: [ {
className: 'dtr-control',
orderable: false,
targets: 0
} ],
order: [1, 'asc'],
responsive: {
details: {
type: 'column'
}
},
"responsive": false,
"pageLength": 100
} );
scrollX: true,
processing: true,
serverSide: true,
ajax: {
url: '<?=HTML_ROOT?>inc/saveAjax.php',
type: 'GET'
},
dom: 'Bfrtip',
buttons: [
{
extend: 'excelHtml5',
text:'Excel',
className: 'excelbtn',
filename: 'Account_details',
title: 'Account Details',
titleAttr: 'Excel',
exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
}, {
extend: 'pdfHtml5',
text:'PSF',
className: 'pdfbtn',
filename: 'Account_details',
title: 'Account Details',
titleAttr: 'PDF',
exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
}, {
extend: 'csv',
text:'CSV',
className: 'csv',
filename: 'Account_details',
title: 'Account Details',
titleAttr: 'Reports',
exportOptions: { columns: [ 0, 1, 2, 3, 4 ] }
}
],
columnDefs: [ {
className: 'dtr-control',
orderable: false,
targets: 0
} ],
order: [1, 'asc'],
responsive: {
details: {
type: 'column'
}
},
"responsive": false,
"pageLength": 100
} );
In save ajax krijg ik dit terug
Code (php)
1
{"draw":"1","columns":[{"data":"0","name":"","searchable":"true","orderable":"false","search":{"value":"","regex":"false"}},{"data":"1","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"2","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"3","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"4","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"5","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"6","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"7","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"8","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"9","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"10","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}},{"data":"11","name":"","searchable":"true","orderable":"true","search":{"value":"","regex":"false"}}],"order":[{"column":"1","dir":"asc"}],"start":"0","length":"100","search":{"value":"","regex":"false"},"_":"1692944175549"}
met print_r krijg ik dit:
Code (php)
1
Array ( [draw] => 1 [columns] => Array ( [0] => Array ( [data] => 0 [name] => [searchable] => true [orderable] => false [search] => Array ( [value] => [regex] => false ) ) [1] => Array ( [data] => 1 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [2] => Array ( [data] => 2 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [3] => Array ( [data] => 3 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [4] => Array ( [data] => 4 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [5] => Array ( [data] => 5 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [6] => Array ( [data] => 6 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [7] => Array ( [data] => 7 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [8] => Array ( [data] => 8 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [9] => Array ( [data] => 9 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [10] => Array ( [data] => 10 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) [11] => Array ( [data] => 11 [name] => [searchable] => true [orderable] => true [search] => Array ( [value] => [regex] => false ) ) ) [order] => Array ( [0] => Array ( [column] => 1 [dir] => asc ) ) [start] => 0 [length] => 100 [search] => Array ( [value] => [regex] => false ) [_] => 1692944175549 )
De kolomnamen en waarden komen er niet in terug.
De knoppen werken bij het downloaden clientside wel, maar ik wil deze nu op de server hebben via PHP.
Hoop dat iemand me hints kan geven igg bedankt!
Verder zou ik de className van je csv button veranderen in csvbtn, dan ben je consequent met de buttons voor Excel en PDF.
Nog een tip: als ik een aantal variaties van variabelennamen heb, begin ik altijd met het algemene deel, gevolgd door het specifieke deel. Dus zo: btn_excel, btn_pdf, btn_csv. Dat leest veel lekkerder/duidelijker.