Categories | Question details Back To List | ||
dhtmlx sub grid loading from XML Hi, While trying to populate a grid with subgrid using XML file, we need to refer to a subgrid XML using it's name. Is there any way where we can use an XML string to load subgrid also. To explain more, can we call loadXMLString function at the place where we provide the name of the XML file to be loaded into the subgrid. We want to use something like <cell type="sub_row_grid">loadXMLString("subgrid.xml")</cell> instead of <cell type="sub_row_grid">subgrid.xml</cell> Regards, Gaurav Arora Answer posted by Support on Feb 04, 2009 09:46 Grid provides onSubGridCreated event which can be used to customize sub-grid loading grid.attachEvent("onSubGridCreated",function(sub,id,ind,value){ //sub - subgrid object //value - value from XML for related cell sub.loadXMLString(any necessary xml string) return false; //block default logic }); Answer posted by Gaurav Arora on Feb 04, 2009 12:36 Hi, The above suggestion worked but the nested grid is hardly visible. It looks like it is inside a very small div. Please suggest. Following is the code snippet that may be useful... <DIV id=gridbox style="BACKGROUND-COLOR: white" height="300px" width="560"></DIV> <SCRIPT> mygrid = new dhtmlXGridObject('gridbox'); mygrid.setImagePath("Grid with subgrid_files/"); mygrid.setHeader("A,Group Id ,Group Name ,Portfolio Manager"); mygrid.setInitWidths("100,150,150,150") mygrid.setColAlign("right,left,left,right") mygrid.setColTypes("sub_row,ro,ro,ro"); mygrid.init(); mygrid.setSkin("modern"); mygrid.loadXML("Grid with subgrid_files/sgrid.xml"); var subXML = '<?xml version="1.0" encoding="UTF-8"?><rows><head><column align="center" type="ro" width="150">A</column><column align="center" type="ro" width="150">GroupID</column><column align="center" type="ro" width="150">Group Name</column><column align="center" type="ro" width="150">Portfolio Manager</column> </head><row><cell type="sub_row_grid" >B</cell><cell>1018</cell><cell>Advanced Gas Company</cell><cell>681</cell></row></rows>'; mygrid.attachEvent("onSubGridCreated", callback); function callback(sgrid,id,ind,val) { sgrid.loadXMLString(subXML); sgrid.enableAutoHeight(true); sgrid.setSizes(true); return false; } </SCRIPT> Thanks, Gaurav Arora Answer posted by Support on Feb 05, 2009 08:35 Please try to use function callback(sgrid,id,ind,val) { sgrid.loadXMLString(subXML); // sgrid.enableAutoHeight(true); - enabled by default , so not really necessary sgid.callEvent("onGridReconstructed",[]) //It must force size updates for all sub-grid hierarchy return false; } |