How to get Item data from my DataStore?

I’m trying to learn how to use dhtmlxDataStore.
The idea is to load several dataStores on my page on which grids, forms, views and charts… can get their datas and also, to get some values and set new variables into my JS script.

Here is my code :

var myData= new dhtmlXDataStore({ url:"data/data.xml", datatype: "xml" });

data.xml contains :

<data> <item id="1"> <Name><![CDATA[Dammann]]></Name> <Department><![CDATA[Legal Department]]></Department> <Gender><![CDATA[Male]]></Gender> </item> <item id="2"> <Name><![CDATA[Barby]]></Name> <Department><![CDATA[Human Resources]]></Department> <Gender><![CDATA[Female]]></Gender> </item> </data>

How can I get the content of “Name” where ID = 2 ?

Reading the API documentation, it looks like I can use the item(id) method.
But using myData.items(2) throws “undefined” using alert().

tried with
var test = myData.item(2);

does not work too :frowning:

var test = myData.item(2); alert(test.Name);

This code must work.
The only tricky point - data loading is async., so you need to catch the moment when data is loaded in datastore.

function check_data(){ alert(myData.item(2).Name); } var myData= new dhtmlXDataStore({ url:"data/data.xml", datatype: "xml" ready:check_data //will trigger after data loading });

Hi Stanislas !
Thanks for your help ! Now it works for me.
However, I’ve never seen anything about this “ready” parameter in the doc.
Where is it documented ?

Regards. :slight_smile:

:frowning: we will update documentation

Basically - ready handler is an alias for onXLE event, so the documented way for the same logic is

var myData= new dhtmlXDataStore({
    datatype: "xml"     


var myData= new dhtmlXDataStore();
myData.load("data/data.xml", "xml", check_data);

long time past and you still didn’t update the document