customizing the print file to include table styling

customizing the print file to include table styling

sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

Greetings,

I am trying different ways to keep the table styling when I print a data table. I am well aware that data tables currently strips all table styling except the main table class. I have began trying a few different things and modifying the buttons.print.js file in order to achieve this.

var a = c.buttons.exportData(d.exportOptions),
                k = function (b, a) {
                    for (var c = '<tr class="' + (this).className + '">', d = 0, e = b.length; d < e; d++) c += "<" + a + ">" + b[d] + "</" + a + ">";
                    return c + "</tr>"
                },

This returns as undefined for the classes...has anyone had any luck out there...or have any tips or examples of what I am trying to achieve?

This question has an accepted answers - jump to answer

Answers

  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

    Here is the link to the complete buttons.print.js file I am working with: LINK

  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0
    edited March 2017

    Myself and my colleague figured this out for anyone that would like to retain classes/styling for the tables when they are trying to print...

          var a = c.buttons.exportData(d.exportOptions),
                    counter = [];
                    k = function (b, a) {
                        if(a != 'th') {
                            counter.push(a);
                        }                    
                        for (var c = "<tr class=" + $('tr:nth-child(' + counter.length + ')').attr('class') + ">", d = 0, e = b.length; d < e; d++) c += "<" + a + ">" + b[d] + "</" + a + ">";
                        return c + "</tr>"
                    },
    

    One thing to note is that this will only work correctly if one data table is on the screen...still working out a way to support multiple tables correctly...

  • MurgyMurgy Posts: 1Questions: 0Answers: 1
    Answer ✓

    This should do the trick:

    var a = c.buttons.exportData(d.exportOptions),
                    counter = [];
                    k = function (b, a) {
                        if(a != 'th') {
                            counter.push(a);
                            //console.log(a);
                        }
                        //console.log(i);
                        for (var c = "<tr class=" + $('#' + i.attr('aria-controls') + ' tr:nth-child(' + counter.length + ')').attr('class') + ">", d = 0, e = b.length; d < e; d++) c += "<" + a + ">" + b[d] + "</" + a + ">";
                        return c + "</tr>"
                    },
    
    
  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

    Murgy you are a gentleman and a scholar

  • sm1l3ysm1l3y Posts: 24Questions: 7Answers: 0

    Also if you need to keep the table id when printing...

     b = '<table id="' + c.table().node().id + '" class="' + c.table().node().className + '">';
    
This discussion has been closed.