How to add row/column with value to datatables csv export

Viewed 466

I am using jquery datatable to display data. I am also exporting a CSV file using the datatable. I need to be able to add a field and value to a specific location on the csv file that is exported. The field and value do not exist on the datatable so currently when I export it, it is only copying what is on the datatable. How do I add a field and value "Totals" to the csv when exported to row 7 column H?

           $('#ar-table').dataTable({
                    'paginate': false,
                    'bDestroy': true,
                    'dom': 'Bfrtip',
                    'buttons': [
                        'print', 'csv', {
                            extend: 'excel', filename: '*', extension: '.xlsx',
                        }, {
                            extend: 'pdfHtml5',
                            orientation: 'landscape',
                            text: 'PDF',
                            title: 'Open A/R - ' + $('#customer-name').val() + ' - ' + today,
                        }, {
                            extend: 'pdfHtml5',
                            orientation: 'landscape',
                            text: 'PDF-L',
                            title: 'Open A/R - ' + $('#customer-name').val() + ' - ' + today,
                        },
                    ],
                    'aLengthMenu': [[25, 50, 100, 200, -1], [25, 50, 100, 200, 'All']],
                    'iDisplayLength': -1,
                });

DATATABLE VIEW

datatableview

CSV EXPORT

[csv view2

1 Answers

I was able to solve this by using the customize key for datatables. Here is a what my code looks now. This is not using a dynamic variable yet. Hardcoded currently but this solves my initial problem.

enter image description here

Related