Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by hepanxi on Jan 03, 2009 22:15
open dhtmlx forum
Unable to perform mygrid.serialize ()

Hi! Last on the grid will save the data to XML, I used to answer: var xml = mygrid.serialize ().
I tried to write an example. However, the browser prompts: Object does not support this property or method. I do not know if there is a problem, please help me to see. Thank you!
Code is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>test.html</title>
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css"
            href="js/grid/skin/dhtmlxgrid.css">
        <link rel="stylesheet" type="text/css"
            href="js/grid/skin/dhtmlxgrid_skins.css">
        <script type="text/javascript"
            src="js/tabbar/codebase/dhtmlxcommon.js"></script>
        <script type="text/javascript" src="js/grid/src/dhtmlxgrid.js"></script>
        <script type="text/javascript" src="js/grid/src/dhtmlxgridcell.js"></script>
    </head>
    <body>
        <table width="600">
            <tr>
                <td>
                    <div id="gridbox" style="width=100%; height=250px;background-color: white; overflow: hidden"></div>
                </td>
                <td width="20"></td>
                <td>
                    <textarea id="mytextarea" style="width: 250px; height: 250px;">
                        <?xml version="1.0" encoding="utf-8"?>
                        <rows>
                        <row id='r1'>
                        <cell>index is 1</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r2'>
                        <cell>index is 2</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r3'>
                        <cell>index is 3</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r4'>
                        <cell>index is 4</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r5'>
                        <cell>index is 5</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r6'>
                        <cell>index is 6</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r7'>
                        <cell>index is 7</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r8'>
                        <cell>index is 8</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r9'>
                        <cell>index is 9</cell>
                        <cell>load turn started from 1</cell>
                        </row>
                        <row id='r10'>
                        <cell>index is 10</cell>
                        </rows>
                </textarea>
                </td>
            </tr>
        <tr>
            <td>
                <a href="javascript:void(0)" onclick="mygrid.setUserData(mygrid.getSelectedId(),prompt('Name:'),prompt('Value:'))">Set UserData to selected row</a><br>
                <a href="javascript:void(0)" onclick="alert(mygrid.getUserData(mygrid.getSelectedId(),prompt('Name:')))">GetUserData from selected row</a>    
            </td>
            <td></td>
            <td>
                <a href="javascript:void(null)" onclick="loadGridContent()">Load Grid from Text Area</a><br>
                <a href="javascript:void(null)" onclick="serializeGrid()">Serialize Grid</a>
            
            </td>
        </tr>
        </table>
        <script>
    function serializeGrid(){
        mygrid.setSerializationLevel(true,true);
        var myXmlStr = mygrid.serialize()
        document.getElementById("mytextarea").value = myXmlStr;
    }
    function loadGridContent(){
        mygrid.clearAll();
        mygrid.loadXMLString(document.getElementById("mytextarea").value)
    }
    mygrid = new dhtmlXGridObject('gridbox');
    mygrid.setImagePath("../../codebase/imgs/");
    mygrid.setHeader("Column A, Column B");
    mygrid.setInitWidths("100,250")
    mygrid.setColAlign("right,left")
    mygrid.setColTypes("ro,ed");
    mygrid.setColSorting("int,str")
    //mygrid.enableBuffering(15);
    mygrid.setSkin("light")
    mygrid.init();
</script>
    </body>
</html>
Answer posted by Support on Jan 09, 2009 09:37
Please beware that serialization supported only in pro version of dhtmlxgrid. 
By the way, used code is correct.