ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: tbum on September 18, 2021, 09:36:49 am

Title: When exporting tree to excel, '-' character is attached.
Post by: tbum on September 18, 2021, 09:36:49 am
I have two questions. Please help.

First, when exporting tree to excel, a '-' character is appended.
Can you change this character to another character?

The second is to create a function that expands only to level 2 nodes among all nodes in the tree and collapses below that level. Which method is the best way? Wouldn't it be better to collapse all nodes and then use expandTo to show level 2?


Code: [Select]

  datagrid = this.getData();
                            var target = 2;
                            var targetLevel = target -1;
                            var targetItem = [];
                            $.each(datagrid,function(i,v){
                                if(targetLevel > v.pq_level){
                                    targetItem.push(v);
                                }
                            });


                            var tree = this.Tree();
                            tree.collapseAll();
                            if(targetItem.length > 0){
                                tree.expandNodes(targetItem);
                            }
Title: Re: When exporting tree to excel, '-' character is attached.
Post by: paramvir on September 20, 2021, 11:12:35 am
1. use eachCell method of pq.excel to iterate over all cells in worksheet and update cell values.

Code: [Select]
listener: function() {
var w = this.exportExcel({ workbook: true, render: true });
pq.excel.eachCell(w.sheets, function( cell, ci, ri, si ){
//do something with each cell.
if(cell.value && cell.value[0]=="-"){
var matches = cell.value.match(/^((-\s)+)(.*)/);
cell.value = "+ ".repeat( matches[1].length ) + matches[3];
}
});
var blob = pq.excel.exportWb({ workbook: w, type: 'blob' });
    saveAs(blob, "pqGrid.xlsx" );
}

https://paramquery.com/pro/api#method-eachCell


2. Looking into it.
Title: Re: When exporting tree to excel, '-' character is attached.
Post by: paramvir on September 20, 2021, 11:46:16 am
Regarding 2nd question, your logic is correct.

If you want to do that during initialization of treegrid, then you can use pq_close property of a node to initialize open / close property of a node.