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

Loading Data

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

myList.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 formats.

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

myList.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.


myList.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


myList.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 file


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)

myList.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 data 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.

myList.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 row and 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.

myList.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:

myList.parse(data, datatype);

Parsing is executed in a synchronous 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:  Parsing XML string

JSON object

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

Related sample:  Parsing JSON object



Related sample:  Parsing HTML data

CSV string

myList.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:  Parsing CSV string

JavaScript array

myList.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:  Parsing 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;
myList.load(url, "mytype");

Related sample:  Custom data type

Back to top