i use this code to export my table to excel in datatable-django.
$(document).ready(function() {
$('#example').DataTable( {
dom: 'Bfrtip',
buttons:
[{extend: 'excelHtml5', text: 'export'}]
} );
} );
I have a table with 72 columns. I only want to export the columns to Excel whose cells sum is not zero. How can I do this?
i want just show the columns with sum>0
2
Answers
You can modify the export options by extending the excelHtml5 button and customizing the resulting Excel file. please find example below that shows how you can achieve this:
Please note that this solution assumes you have the necessary JavaScript and CSS files for the DataTable library and that you have initialized your DataTable with the appropriate options.
Use
customizedData
You can use
customizedData
callback functionExplanation
We retrieve the column data using
table.columns().data()
and then calculate the sum of each column, filtering out the columns whose sum is not greater than zero.After that we assign these filtered columns to
data.body
to replace the original data for export.