EasyUI Forum
April 19, 2024, 10:20:15 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED] Tree - Export tree to pdf  (Read 5547 times)
jega
Full Member
***
Posts: 190


View Profile
« 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
« Last Edit: June 06, 2018, 02:55:53 AM by jega » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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();
Logged
jega
Full Member
***
Posts: 190


View Profile
« Reply #2 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

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!