Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by alberlau on May 05, 2009 23:42
open dhtmlx forum
How to show in grid cell of type tree text instead of id

Hello

I have the following definition xml for grid:

<?xml version="1.0" encoding="UTF-8"?>
<rows>
<head>
<column id="colAcc" type="stree" width="100">Sąskaita</column>
<column id="colDebit" type="ed" width="100">Kreditas</column>
<column id="colCredit" type="ed" width="100">Debetas</column>
<column id="colNote" type="ed" width="300">Pastaba</column>
<column type="ro"></column>
</head>
<row id="41">
<cell>1070</cell>
<cell>11,00</cell>
<cell></cell>
<cell/>
<cell><![CDATA[<a class="button" href="#" onclick="delRow('41')">Pašalinti</a>]]></cell>
</row>
</rows>

and following fragment of xml for stree embedded in first column:

<?xml version="1.0" encoding="UTF-8"?>
<tree id="0">
<item id="1001" text="1-TURTAS" open="true" child="6">
<item id="1008" text="1.10-PINIGAI" open="true" child="4">
<item id="1031" text="1.10.20-PINIGAI KASOJE" open="true" child="24">
<item id="1070" text="1.10.20.0301-PIRMAS KASININKAS - PINIGAI" child="0">
<userdata name="childrenCount">0</userdata>
</item>

In row :
<row id="41">
<cell>1070</cell>
I have reference to tree item with id 1070. But in grid first column i see number 1070 instead of text="1.10.20.0301-PIRMAS KASININKAS - PINIGAI". My question is: how i can resolve id to text. In first cell there should be 1.10.20.0301-PIRMAS KASININKAS - PINIGAI instead of id 1070.

Respectfully
Albertas
Answer posted by dhxSupport on May 06, 2009 02:12
Please check if you are using mygrid.setSubTree(tree,0). This method attaches an external tree as an editor. The parameters here are: 
subtree - a tree instance that will be used as an editor;
column - a column in the main grid to which the sub-tree will be linked.
Answer posted by alberlau on May 06, 2009 03:38
Yes i'm using setSubTree:

         var tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
        tree.setImagePath("<c:url value="/js/tree/imgs/"/>");
        var mygrid = new dhtmlXGridObject('gridbox');
        mygrid.setImagePath("<c:url value="/js/grid/imgs/"/>");
        mygrid.enableAlterCss("even","odd");
        mygrid.i18n.decimal_separator=",";
        mygrid.i18n.group_separator="";
        mygrid.attachEvent("onKeyPress",evKeyPress);
        mygrid.attachEvent("onEditCell",evOnEditCell);
        mygrid.loadXML("batchItems.htm?id=${id}");
        var dp = new dataProcessor("batchItems.htm");
        dp.setTransactionMode("POST");
        dp.setVerificator(0,accountVerificator);
        dp.setUpdateMode("cell");
        //dp.enableDataNames(true);
        dp.init(mygrid);
        tree.setXMLAutoLoading("coaService.htm?fetchAccounts");
        tree.attachEvent("onSelect",evTreeSelect);
        tree.loadXML("coaService.htm?loadRoots&id=${id}", function() {
            mygrid.setSubTree(tree, 0, 0);
        });

Note: ${id} and <c:url is JSP syntax.

Answer posted by Alex (support) on May 06, 2009 05:15

Please, try to initilize grid after tree xml is loaded. In this case grid can find the corresponding text in tree:

var tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
tree.setImagePath("<c:url value="/js/tree/imgs/"/>");
tree.setXMLAutoLoading("coaService.htm?fetchAccounts");
tree.attachEvent("onSelect",evTreeSelect);
tree.loadXML("coaService.htm?loadRoots&id=${id}", function() {
 var mygrid = new dhtmlXGridObject('gridbox');
 mygrid.setSubTree(tree, 0, 0);
 ...
 ...
 mygrid.loadXML("batchItems.htm?id=${id}");
 
});

 


Answer posted on May 06, 2009 05:47
After rewrite code as below, text is resolved from id.

        var mygrid = new dhtmlXGridObject('gridbox');
         var tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
        tree.setImagePath("<c:url value="/js/tree/imgs/"/>");
        tree.setXMLAutoLoading("coaService.htm?fetchAccounts");
        tree.attachEvent("onSelect",evTreeSelect);
        tree.loadXML("coaService.htm?loadRoots&id=${id}", function() {
            mygrid.setSubTree(tree, 0, 0);
            mygrid.setImagePath("<c:url value="/js/grid/imgs/"/>");
            mygrid.enableAlterCss("even","odd");
            mygrid.i18n.decimal_separator=",";
            mygrid.i18n.group_separator="";
            mygrid.attachEvent("onKeyPress",evKeyPress);
            mygrid.attachEvent("onEditCell",evOnEditCell);
            mygrid.loadXML("batchItems.htm?id=${id}");
            var dp = new dataProcessor("batchItems.htm");
            dp.setTransactionMode("POST");
            dp.setVerificator(0,accountVerificator);
            dp.setUpdateMode("cell");
            //dp.enableDataNames(true);
            dp.init(mygrid);
        });

Very nice widgets, i got approvement from managment to purchase professional version :)