Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Micheal on Sep 16, 2008 11:46
open dhtmlx forum
Saving back to XML with standard version of dhtmlxgrid

I am using the free standard version of dhtmlxgrid. I have successfully added it to my website, but now I want to be able to save the data that I have edited back into the XML file.

Is this something that I will have to buy the Pro version to do? From all my research it looks like I would have to but I figure I should ask.

If not could I get some help with code to do that save.

Thanks a whole bunch in advance. I think I will buy this software in the future, but at the moment I can't afford to buy the Pro version.



This is the code I am using right now, and I set it up from the basic guide that was provided in the download.

var mygrid;
function doInitGrid(){
mygrid = new dhtmlXGridObject('mygrid_container');
mygrid.setImagePath("codebase/imgs/");
mygrid.setHeader("Name,E-Mail Address,Territory,Ext");
mygrid.setInitWidths("200,215,215,70");
mygrid.setColAlign("left,left,left,left");
mygrid.setSkin("light");
mygrid.init();
mygrid.loadXML("reps.xml");
}
function addRow(){
var newId = (new Date()).valueOf()
mygrid.addRow(newId,"",mygrid.getRowsNum())
mygrid.selectRow(mygrid.getRowIndex(newId),false,false,true);
}
function removeRow(){
var selId = mygrid.getSelectedId()
mygrid.deleteRow(selId);
}

===================

here is the HTML

<body onload="doInitGrid();">
<div align="center">
<div id="containerPage">
        <div align="left">
            <?php include("../includes/i_nav.php"); ?>
            <div id="containerBody">
                <div id="mygrid_container" style="width:700px;height:400px;margin:0px auto;"></div>
                <div style="width:700px;margin:0px auto;">
                    <p> </p>
                    <p><button onclick="addRow()">Add Row</button>  
                    <button onclick="removeRow()">Remove Row</button>
                    </p>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
Answer posted by Support on Sep 17, 2008 10:31
There is no opportunuty to save data directly into the xml file.

You can send changed data to some server-side program, which should save data into some database. XML stream for the loadXML can be generated by any server-script as well.

In order to get changed data you can use event handlers (dhtmlxGrid/doc/events.html).

The professional version provides additional functionalities to get grid data:

1) allows to serialize grid to the xml string:

var xml_str = grid.serialize();

2) and there is the DataProcessor functionality which gives an opportunity to send changed data to the server easily.