• Resolved markswift

    (@markswift)


    Hi,

    Firstly, an absolutely awesome extension – thank you for your hard work.

    I’m trying to reproduce this code to change the cell background on export via PDF:

    $(document).ready( function () {
      var table = $('#example').DataTable({
        dom: 'Bfrtip',
        buttons: [
          {
            extend: "pdfHtml5",
            customize: function(doc) {
              console.log(table.column(3).data().toArray())
              age = table.column(3).data().toArray();
              for (var i = 0; i < age.length; i++) {
                if (age[i] < 40) {
                  doc.content[1].table.body[i+1][3].fillColor = 'blue';
                }
              }
            }
          }
        ]
      });
    } );

    I’ve been trying for over 2 hours and am not sure how to best implement it, as of now I’ve always used the ‘custom commands’ section of the table to add functionality, but this time I’m stuck :-/

Viewing 1 replies (of 1 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Using the “Custom Commands” text field is correct here, but you’ll have to use only a piece of this code:

    "dom": "Bfrtip",
    "buttons": [ {
    	"extend": "pdfHtml5",
    	"customize": function(doc) {
    		console.log(table.column(3).data().toArray())
    		age = table.column(3).data().toArray();
    		for (var i = 0; i < age.length; i++) {
    			if (age[i] < 40) {
    				doc.content[1].table.body[i+1][3].fillColor = "blue";
    			}
    		}
    	}
    } ]

    Also, the TablePress DataTables Buttons Extension has to be activated and you need to use datatables_buttons="pdf" in the Shortcode.

    Regards,
    Tobias

Viewing 1 replies (of 1 total)

The topic ‘Cell background fill on PDF export’ is closed to new replies.