Custom data format

Hi,

following the documentation here: http://docs.dhtmlx.com/grid__data_formats.html#customdataformat

I was able to easily modify the custom XML to handle standard JSON:

function process_strongloop_row(r, json) {
	//sets just a plain array as no custom attributes are needed
	r._attrs = {};
	for (j = 0; j < r.childNodes.length; j++) r.childNodes[j]._attrs = {};
	//finishes data loading

	var data = _(json).toArray()
	this._fillRow(r, data);
	return r;
}

function get_strongloop_data() {

}

function process_strongloop(data) {
	'use strict';

	this._parsing = true;

	var json = JSON.parse(data.response);

	for (var i = 0; i < json.length; i++) {
		var id = this.getUID();
		this.rowsBuffer[i] = { //stores references to each row element
			idd: id,
			data: json[i],
			_parser: this._process_strongloop_row, //cell parser method
			//_locator: this._get_strongloop_data    //data locator method
		};

		this.rowsAr[id] = json[i]; //stores id reference
	}

	this.render_dataset(); //forces update of grid's view after data loading
	this._parsing = false;
}

As you can see - it is a pretty straight forward handling of JSON structure, and simply making it as an Array per row.
The reason it was needed - I’m using StrongLoop CRUD methods, which are returning records/objects from the database without the “rows” array.

Couple of questions:

  1. Isn’t there a simpler way of doing it instead of custom data processor?
    shouldn’t there by an additional type on DHTMLX level - maybe json_rows which is only accepting the rows - just like this Data processor?
  2. I looked online - and I couldn’t find an example for the _locator method. Any one has a reference to a working example?

Thanks,
Shahar

Here you can find supported data formats including the standard json and json array:
docs.dhtmlx.com/grid__data_forma … jsonformat

Maybe I got misunderstood.

This is an example of StrongLoop CRUD returns as the Response Body:

[
  {
    "tracking": "1ZY796500332529736",
    "pieces": 1,
    "packageType": "box",
    "id": "56a671f3209f905611cda21b"
  },
  {
    "tracking": "1ZY796523432529736",
    "pieces": 1,
    "packageType": "box",
    "id": "56a690a0209f905611cda21c"
  }
]

This means I cannot use json array or json - which is why I had to implement custom data format handlers.

I’m still missing the data locator method - which that URL you mentioned does not have an example of.

Here is the part of the provided tutorial:

@sematik thanks.

So I was able to do the following:
grid.load(“config/grid.json”,“json”);
which grid.json is:

{
 head:[
   {id:"tracking",   type:"ro",    sort:"str", value:"Tracking#"},
   {id:"pieces",    type:"ro",      sort:"int", value:"Pieces"},
   {id:"packageType",   type:"ro",     sort:"str", value:"Type"},
   {id:"id",    type:"ro", sort:"str", value:"id", hidden:true},
 ],
 rows: []
}

which managed to set the grid configuration, and only then, the following worked:
grid.load(‘http://10.0.0.215:3000/api/packages’, ‘js’);
which is great!

But I need dhtmlXDataStore to work the same way… and I can’t figure out how.

Unfortunately it is not available to init the grid from the js using the datastore.