dhtmlxTreeGrid Dynamic loading of sub items : can we use mutliple KidsXmlFile?
I want to load dynamically all subitem from each request but i am not able to add mutliple KidsXmlFile to a tree, and when i click on the tree node child nodes keep adding based on number of clicks,
I have implemented a server side to calculate and return the data to populate the branch given the supplied row id.
My sample code
mygrid = new dhtmlXGridObject(‘gridbox’);
mygrid.imgURL = “<%=request.getContextPath()%>/imgs/icons_greenfolders/”;
mygrid.selMultiRows = true;
mygrid.setHeader(“Column A,Column B,Column C,Column D”);
mygrid.setInitWidths(“100,100,100,100”)
mygrid.setColAlign(“left,left,left,center”)
mygrid.setColTypes(“tree,ro,ro,ch”);
mygrid.setColSorting(“str,str,str,na”)
mygrid.setSkin(“clear”);
mygrid.init();
mygrid.enableSmartRendering(true);
myform = document.getElementsByTagName(‘form’).item(0);
sessionid = myform.subsessionId.value;
mygrid.kidsXmlFile="<%= request.getContextPath() %>" + “/secure/changeControl1.do?method=changeControl1DataHonda&subsessionId=” + sessionid;
mygrid.kidsXmlFile="<%= request.getContextPath() %>" + “/secure/changeControl1.do?method=changeControl1DataBWM&subsessionId=” + sessionid;
thisURL = “<%= request.getContextPath() %>” + “/secure/changeControl1.do?method=changeControl1Data&subsessionId=” + sessionid;
mygrid.loadXML( thisURL );
public ActionForward changeControl1Data(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DFContext dfContext = SessionHelper.getSession(request);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
String contextPath = request.getContextPath();
ps.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
“” +
“<row id=“honda” selected=“1” call=“1” xmlkids=“1”>”+
“<cell image=“folder.gif”>Honda”+
“”+
“<row id=“bmw” selected=“5” call=“5” xmlkids=“5”><cell image=“folder.gif”>BMW”+
“”+
“<row id=“vw”><cell image=“folder.gif”>Volkswagen”+
“”+
“<row id=“mazda”><cell image=“folder.gif”>Mazda”+
“”+
“”);
return null
}
public ActionForward changeControl1DataHonda(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DFContext dfContext = SessionHelper.getSession(request);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
String contextPath = request.getContextPath();
ps.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
“<rows parent=“honda”><row id=“honda1” xmlkids=“1”>name 147,100 3.2L333”+
“<row id=“honda2” xmlkids=“1”>name 247,1003.2L333”+
“”);
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
return null;
}
When you are using kidsXmlFile with TreeGrid, each time when grid opens branch, call to remote URL occurs, the result url built from kidsXmlFile and ID of item opened. So you can use same url for all items, and receive the ID of related item in same time.
For example if you define
mygrid.kidsXmlFile="<%= request.getContextPath() %>" + “/secure/changeControl1.do?subsessionId=” + sessionid;
when opening “honda” item, the url be
mygrid.kidsXmlFile="<%= request.getContextPath() %>" + “/secure/changeControl1.do?subsessionId=” + sessionid&id=honda
so, your server side code can get info, for which branch data need to be outputed.
( The oncoming build will introduce onDynXLS event, which will add full control on dyn. url building, but it not available in public build yet )