How to load external json file into dhtmlx Grid?

515 views Asked by At

Hi By using below code I can load XML data into DHTMLXGrid, its working fine. But when I try to load same data in Json format its not working. I request you someone to help me on this. I tried everything on this code using json, but :( :(. Your help is much appreciated , i need a working example.

<script type="text/javascript">
        dhtmlx.image_path = "codebase/imgs/";
         dhtmlxEvent(window,"load",function(){ 
            var layout = new dhtmlXLayoutObject(document.body,"2U"); 
            layout.cells("a").setText("Contacts");   
            layout.cells("b").setText("Contact Details"); 
            layout.cells("b").setWidth(500); 
            var menu = layout.attachMenu(); 
            menu.setIconsPath("icons/");
            menu.loadStruct("data/menu.xml");
            var toolbar = layout.attachToolbar(); 
            toolbar.setIconsPath("icons/");
            toolbar.loadStruct("data/toolbar.xml");

            var contactsGrid = layout.cells("a").attachGrid();
            contactsGrid.setHeader("Name,Last Name,Email");   //sets the headers of columns
            contactsGrid.setColumnIds("fname,lname,email");         //sets the columns' ids
            contactsGrid.setInitWidths("250,250,*");   //sets the initial widths of columns
            contactsGrid.setColAlign("left,left,left");     //sets the alignment of columns
            contactsGrid.setColTypes("ro,ro,ro");               //sets the types of columns
            contactsGrid.setColSorting("str,str,str");  //sets the sorting types of columns
            contactsGrid.init();
            contactsGrid.loadXML("data/data.xml",true,true);
});

</script>
1

There are 1 answers

1
madhangi On

give contextpath and try.

contactsGrid.loadXML("<%=request.getContextPath()%>/data/data.json","json");