Check documentation for the latest version of dhtmlxSuite Loading Data DHTMLX Docs

Loading Data

To load data from some external file you can use the load command:

view.load(url, datatype);

It takes the path to the file and a necessary data type as parameters. Where a data type can be: "json","xml","jsarray","csv","html".

Note that:

  • JSON and XML are the fastest for loading and the only formats which support dynamic loading.

  • Loading is asynchronous, which means you need to catch the end of loading before executing any commands against the data.

view.load(url, function(){
    alert("data is really loaded"); 
    //any operations with data can be placed here

If the datatype parameter is skipped, the operation will try to process the incoming data as XML.


view.load("some.json", "json");

where some.json contains a value similar to the following one:


  "Maintainer":"Stefano Canepa"
  "Maintainer":"Debian Games Team"
  "Maintainer":"Debian Games Team"

The object can contain any number of properties and all of them will be available in templates.

The "id" property will be used as the ID of object. If there is no such a property, the component will create random IDs for each object.

Related sample:  Loading data from JSON file


view.load("some.xml", "xml");

There aren't any requirements for incoming XML (it can be in any format), all the top level tags will be converted into objects.


    <item id="1">
        <Maintainer><![CDATA[Stefano Canepa]]></Maintainer>
    <item id="2">
        <Maintainer><![CDATA[Debian Games Team]]></Maintainer>

The names of the top level and the second level tags don't matter.

The attributes of the top level tags (item in the snippet above) and values of nested tags will be available as properties in the template and for scripting.

If you want to process only the tags with specific names you can change the xpath used for data collecting:

dhtmlx.dataDriver.xml.records = "/data/item"; //select only item tags

Related sample:  Loading data from xml


The processing works similar to that of XML, but will react only on <li> tags inside of the data (it makes no practical sense for loading from an url, exists just for consistence)

view.load("some.html", "html");


    <li id="1" version="20080210-1.1" maintainer="Stefano Canepa">acx100-source</li>
    <li id="2" version="7.0-1" maintainer="Debian Games Team">alien-arena-browser</li>
    <li id="3" version="7.0-1" maintainer="Debian Games Team">alien-arena-server</li>

The key-tag can be changed by using: = "DIV";

Related sample:  Loading from html file


Data in CSV doesn't have names for columns, so they are autonamed: the first column is accessible as "data0", the second one - as "data1", etc. IDs are auto-generated.

view.load("some.csv", "csv");


"1", "acx100-source", "20080210-1.1", "Stefano Canepa"
"2", "alien-arena-browser", "7.0-1", "Debian Games Team"
"3", "alien-arena-server", "7.0-1", "Debian Games Team"

You can configure a row and a line separators as:

dhtmlx.dataDriver.csv.row = "\n";
dhtmlx.dataDriver.csv.cell= ",";

Related sample:  Loading data from CSV file


Data in JS array doesn't have names for columns, so they are autonamed: the first column is accessible as "data0", the second as "data1" and etc. IDs are auto-generated.

view.load("some.js", "jsarray");


[["1", "acx100-source", "20080210-1.1", "Stefano Canepa"],
["2", "alien-arena-browser", "7.0-1", "Debian Games Team"],
["3", "alien-arena-server", "7.0-1", "Debian Games Team"]]

Related sample:  Loading data from JS array


When the data is already available on the client side, you can use the code:

view.parse(data, datatype);

Parsing is executed in sync way, so new items are ready for operations after the command execution.

Parsing can be used with all the above mentioned data types.

XML string

    <item id="1">
        <Maintainer><![CDATA[Stefano Canepa]]></Maintainer>

Related sample:  Parse data from xml string

JSON object

  "Maintainer":"Stefano Canepa"
  "Maintainer":"Debian Games Team"
  "Maintainer":"Debian Games Team"

Related sample:  Parse data from JSON object

HTML string


Related sample:  Parse HTML list

CSV string

view.parse('"1", "acx100-source", "20080210-1.1", "Stefano Canepa"
  \n"2", "alien-arena-browser", "7.0-1", "Debian Games Team"
  \n"3", "alien-arena-server", "7.0-1", "Debian Games Team"',"csv");

Related sample:  Parse from CSV string

JavaScript array

view.parse([["1", "acx100-source", "20080210-1.1", "Stefano Canepa"],
["2", "alien-arena-browser", "7.0-1", "Debian Games Team"],
["3", "alien-arena-server", "7.0-1", "Debian Games Team"]],"jsarray");

Related sample:  Parse JS array

Custom Data Types

If the above loading types are not enough, you can create a custom one.

        var result = {}; = data[0];
        result.Package       = data[1];
        result.Version       = data[2];
        result.Maintainer    = data[3];   
        return result;
view.load(url, "mytype");

Related sample:  Custom data type

Back to top