javascript – Export data table to PDF

Question:

I'm using JS Webix plugin to create dynamic grid . It has a functionality to export to PDF/Excel, on the website it has the following example:

grid = new webix.ui({
    view:"datatable",
    columns:[...],
    "export":true
});

and to activate, the button:

<input type="button" value="Get as PDF" style='width:400px;margin:25px;' onclick="grid.exportToPDF();">

Where grid is the instance of webix.ui that contains the datatable


How do I export if the datatable is inside a layout? Example:

new webix.ui({
    type:"line", id:"a1", rows:[
        {type:"head", padding:0, responsive:"a1", cols:[
                {template:"<?=$rel->getHeader_logo()?>", css:"cabecalho-webix", height:84, minWidth:200},
                {template:"<?=$rel->getHeader_titulo()?>", css:"cabecalho-webix", height:84, minWidth:300},
                {template:"<?=$rel->getHeader_dataemissao()?>", css:"cabecalho-webix", height:84, minWidth:200}
        ]},
        {type:"line", padding:0, responsive:"a1", cols:[
            {
                container:"testA",
                view:"datatable",
                columns: <?= $json; ?>,
                footer:false,
                autoheight:false,
                data:<?= $json_body; ?>,
                scrollAlignY:true,
                export:true,
                resizeColumn:true,
                resizeRow:false,
                dragColumn:true
            }
        ]},
        {type:"line", padding:0, responsive:"a1", cols:[
            {template:"<span id='imprimir' onclick='printGrid();'><img src='images/bt_imprimir.png'></span>", height:60}
        ]}
    ]
}).show();

Answer:

First enter an ID:

{
    container:"testA",
    view:"datatable",
    columns: <?= $json; ?>,

    id: "iddatatable"

    footer:false,
    autoheight:false,
    data:<?= $json_body; ?>,
    scrollAlignY:true,
    export:true,
    resizeColumn:true,
    resizeRow:false,
    dragColumn:true
}

Call by ID:

$$('iddatatable').exportToPDF();
Scroll to Top