Add Autofilter to Excel Column Headers on Export
Add Autofilter to Excel Column Headers on Export
jlock
Posts: 14Questions: 4Answers: 0
I cannot figure out how to add autofilter to the column header in the excel worksheet when exported. Has anyone done this successfully and can share some code? I have tried adjusting the xlm but it does not work.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'm not aware of anyone having done this I'm afraid. You would need to use the
customize
callback of theexcelHtml5
button type to modify the xlsx file's XML to add that.I think you would probably need to reverse engineer a solution from an Excel file that uses an Autofilter.
Allan
Found this from @F12Magic and it worked perfectly, thank you!
DataTables initialization: Use the customize option to add AUTO FILTERS to the column headers. Required is the function createCellPos (n) ,copied from buttons.html5.js, which you need to insert in your own script. We can't call it directly, because it's a private function in that plugin script.
I have made some small changes in the source code of the autoFilter function in order to work for me and to suit my needs:
It may be helpful to someone....
I've decided to go ahead and provide the ability to enable this feature in Buttons itself. There is now a
autoFilter
option which can be used to enable the auto filter feature in Excel:Commit
This will be in 1.5.4 or you can grab the latest source from GitHub or the nightly which will be up to date shortly.
Allan