Enable header filters in excel export using jquery datatables -


i'm trying enable filters excel top row / header file generated table data using jquery datatables library.

i've followed tutorial https://datatables.net/extensions/buttons/examples/initialisation/export.html , works great , generated excel file looks below.

enter image description here

as can see in pic, there no filters top row. know can enable filters in excel file after opening. i'm trying when excel file gets generated.

so, exported excel file should below.

enter image description here

you can see highlights in red circle filters.

so wondering if it's possible , suggestions how accomplish highly appreciated.

thank you.

you can enables filters automatically changing excel file schema in file buttons.html5.js.

in buttons.html5.js file, can find below code.

// excel - pre-defined strings build minimal xlsx file var excelstrings = {     "_rels/.rels": '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\ <relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\     <relationship id="rid1" type="http://schemas.openxmlformats.org/officedocument/2006/relationships/officedocument" target="xl/workbook.xml"/>\ </relationships>',      "xl/_rels/workbook.xml.rels": '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\ <relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">\     <relationship id="rid1" type="http://schemas.openxmlformats.org/officedocument/2006/relationships/worksheet" target="worksheets/sheet1.xml"/>\ </relationships>',      "[content_types].xml": '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\ <types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">\     <default extension="xml" contenttype="application/xml"/>\     <default extension="rels" contenttype="application/vnd.openxmlformats-package.relationships+xml"/>\     <default extension="jpeg" contenttype="image/jpeg"/>\     <override partname="/xl/workbook.xml" contenttype="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/>\     <override partname="/xl/worksheets/sheet1.xml" contenttype="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/>\ </types>',      "xl/workbook.xml": '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\ <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officedocument/2006/relationships">\     <fileversion appname="xl" lastedited="5" lowestedited="5" rupbuild="24816"/>\     <workbookpr showinkannotation="0" autocompresspictures="0"/>\     <bookviews>\         <workbookview xwindow="0" ywindow="0" windowwidth="25600" windowheight="19020" tabratio="500"/>\     </bookviews>\     <sheets>\         <sheet name="__sheet_name__" sheetid="1" r:id="rid1"/>\     </sheets>\ </workbook>',      "xl/worksheets/sheet1.xml": '<?xml version="1.0" encoding="utf-8" standalone="yes"?>\ <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officedocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac">\     <sheetdata>\         __data__\     </sheetdata>\ </worksheet>' }; 

you have update above object below.

excelstrings["xl/worksheets/sheet1.xml"] = '<?xml version="1.0" encoding="utf-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officedocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:ignorable="x14ac" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"><sheetdata>__data__</sheetdata><autofilter ref="a1:g1"/></worksheet>'; 

the difference appended <autofilter ref="a1:g1"/>.

please note ref="a1:g1" columns auto filter enabled.

this how solved issue of enabling auto filters.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -