Set table width to 100% on PDF export in Datatables

I've been using DataTables a lot these days, it's good. Actually, it's a very good plug-in for displaying data in table (haha), with lots of interaction.

Few and should be implemented feature:

  • Can't export multiple table headers
  • API for table width in PDF Export 
  • Adding header and footer for Excel Export
DataTables uses pdfmake library for its pdf export module.

Sample output of pdf


To make the table width 100%, as per pdfmake documentation we should set its width to "*".

Here it goes:

Edit the datatables JS file, find t.table.widths="auto", change it to t.table.widths="*".

You might want to change the alignment of the table header also:

Find 
tableHeader:{bold:!0,fontSize:11,color:"white",fillColor:"#2d4154",alignment:"center"

Set the alignment to left.
sample output after the tweak



Popular posts from this blog

Publish PostGIS Layers in GeoServer Automatically using cURL and REST

Implementing Datatables in Django

Schedule Loading of Shapefile into a PostgreSQL Database