EasyUI Forum

General Category => General Discussion => Topic started by: jega on May 30, 2018, 01:37:30 PM



Title: [SOLVED] Tree - Export tree to pdf
Post by: jega on May 30, 2018, 01:37:30 PM
Hi.

Have not the time right now to make some test, so i will ask here.

Is there any way to export a tree also ??

Have a tree with 5 nodes and a lot of childs. I need to expand a node, and all childs (can be done easy). With that tree expanded, i need to export it to at least an pdf, but xls will also be nice. Or maybe an image

Jesper


Title: Re: Tree - Export tree / treegrid to xls / pdf
Post by: stworthy on May 31, 2018, 08:41:05 PM
Define the functions to translate the tree data.
Code:
function translateTreeData(children, depth){
depth = depth || 0;
if (!children || !children.length){return []}
var rows = [];
$.map(children, function(item){
var node = {text:item.text,depth:depth};
rows.push(node);
rows = rows.concat(translateTreeData(item.children, depth+1));
});
return rows;
}
function toArray(rows){
var body = [];
for(var i=0; i<rows.length; i++){
var row = rows[i];
var text = row.text;
for(var j=0; j<row.depth; j++){
text = '-' + text;
}
var item = [text];

body.push(item);
}
return body;
}

Use the pdfmake to export pdf.
Code:
var roots = $('#tt').tree('getRoots');
var rows = translateTreeData(roots);
var body = toArray(rows);
var docDefinition = {
    content: [{
        table: {
            headerRows: 0,
            widths: ['*'],
            body: body
        }
    }]
};
pdfMake.createPdf(docDefinition).open();


Title: Re: Tree - Export tree / treegrid to xls / pdf
Post by: jega on June 06, 2018, 02:55:15 AM
Hi stworthy

Have worked the last 3 days on the sample code.

Have now a full working tree export. The tree have checkbox, so that only checked are exported. Color choose on folder and document in tree.



Thanks for your help