Check documentation for the latest version of dhtmlxSuite Step 3. Load Data to the Grid DHTMLX Docs

Step 3. Load Data to the Grid

Now it's time to load data to the grid.

dhtmlxGrid can take data of 4 formats: XML (default), JSON, JSArray, CSV. And in this article we'll describe loading data of the default format, i.e. XML.

XML format that is used for grid's data is intuitively clear. Generally, it consists of the rows with cells, containing some basic data. Each row should have a unique identifier (it's important for the grid's ability to distinguish one row from another).

For our sample we will create a structure with rows that have 3 cells inside (as soon as we set 3 columns in the grid) and save it in a separate file.

To load data to the grid:
  1. Create an XML file in the "basic_grid " folder and name it "data.xml ".
  2. Open the "data.xml " file and add the following code into it:

    "data.xml" file

    <?xml version="1.0" encoding="UTF-8"?>
        <row id="a">
            <cell>book 1</cell>   //1st column
            <cell>300</cell>      //2nd column
            <cell>50</cell>       //3rd column
        <row id="b">
            <cell>book 2</cell>
        <row id="c">
            <cell>book 3</cell>
  3. Call the load() method to load data from the "data.xml " file to the grid:

    "index.html" file

        mygrid = new dhtmlXGridObject("mygrid_container");

Back to top