DHTMLX Touch documentation

How to create your own data type?

DataDriver is an object that defines a data type.
DHTMLX gives at your disposal 5 main drivers: json, xml, html, csv, jsarray plus additional dhtmlxgrid - data from dhtmlxGrid (compatability_grid.js).
Therewith, you can specify your own data type - create your own driver.

Let's consider this in detail.

The structure of the creation is the following:

dhtmlx.DataDriver.some={ //some - the name of the type
	toObject:function(text,xml){
                ...
		return text; 
	},
	getRecords:function(data){ 
                var result = [];
                ...
		return result;
	},
	getDetails:function(data){
                var result = {}
                ... 
		return result;
	},
	getInfo:function(data){
		return { 
		 _size:some, 
		 _from:other 
		};
	}
};

For a start, we have some data that we want to use as a new data type. The first thing we need to make with this data - convertion into the intermediate object (an object that will be used as input parameter in the other functions ).
So, our first step - toObject(text, xml) function. The function is called after data loading or directly in the parse method and returns the intermediate data object.

  • text - incoming data
  • xml - xml object (for xml loading scenario. For other data type can be ignored)

Then, we form an array of records using data from our intermediate object.
The second step - getRecords(data) function

  • data - the intermediate object from the previous step

Having an array of records we need to specify a set of properties for each single record.
The third step - getDetails(data)

  • data - an element of the array from the previous step

The last action has sense just for dynamic data loading scenarios. It's a function that gets count of data and position at which new data needs to be inserted
The forth step - getInfo(data). The function returns count of data and the appropriate position mentioned above: '0' if a value is unknown or unnessasary.

  • data - the intermediate object from the previous step

So, making these four or even three steps you can specify any data type and then use it while developing.