Search code examples
jqgrid

jqGrid Export To PDF (Highlighted Row)


I'm exporting a jqGrid to PDF that works fine with one exception. The printout doesn't include highlighted rows in the grid. For example, I'm highlighting certain row as follows

$("#inventoryOnHandSearchGrid").jqGrid('setRowData', i, false, "css-class");

The "css-class" is just a css class that sets the background color

background-color: lightyellow;

This is the code to export

 $("#inventoryOnHandSearchGrid").jqGrid("exportToPdf", {
        title: 'Quantity On Hand',
        orientation: 'landscape',
        pageSize: 'A3',
        description: "Date: " + todaysDate,
        customSettings: null,
        download: 'download',
        includeLabels: true,
        includeGroupHeader: true,
        includeFooter: true,
        fileName: "qtyOnHand.pdf"
    })

Is this possible to have the export show the highlighted rows?


Solution

  • In Guriddo jqGrid the exportToPdf does not convert html to pdf - it uses pdfMake to generate the pdf based on the raw array data.

    Partial solution is to use onBeforeExport event to modify document so that it can color a rows by condition.

    The example below make export to pdf in zebra table

    $("#inventoryOnHandSearchGrid").jqGrid("exportToPdf", {
    ...
        onBeforeExport : function( doc ) {
            doc.content[2].layout = {};
            doc.content[2].layout.fillColor = function(rowIndex, node) {
                return (rowIndex % 2 === 0) ? '#CCCCCC' : null;
            };
        },
    ...
    });
    

    For more information look at the pdfMake documentation