dhtmlxGrid and JSON from web services

Yesterday I read this:
dhtmlxGrid can now load data from common JSON format (the older version of the grid required a specific JSON structure). This simplifies the integration with external web services that return the data in JSON format.

THen I downloaded and installed the version: Suit 3.5 Standard Edition.
Today from 5:30 to 20:15 I’ve read and tried in every way how to load data JSON for the grid, but I just found this command:

function buildInterface(){
    //entire code for interface init will go here
    myGrid = new dhtmlXGridObject("mygrid");
    myGrid.setImagePath("../static/js/Codebase/imgs/");
    myGrid.setHeader("Marca,Descrizione,U.m.,Prezzo");
    myGrid.setInitWidths("200,*,150,150");
    myGrid.setColAlign("right,right,right,left");
    myGrid.setSkin("light");
    myGrid.init();
    myGrid.load("aeldati","json");
}
dhtmlxEvent(window,"load", buildInterface);

I’m definitely making a big mistake because the request to the server is:
GET /aeldati
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Status: 200 OK. /aeldati

While a normal request JSON looks like this:
GET /herdati
Accept: application/json, text/javascript, /; q=0.01
Status: 200 OK. /herdati

My format is like this:

[{"idum":4,"descrizione":"Bavette 500 gr.","marca":"Federicci","tid":"oT/mIfLdggVpd+eUS","prezzo":2.1},{ ...................}]

Thank you in advance for your help.

Please, try to use:

myGrid.load("aeldati","js");

Note: it will be necessary to add ids to your columns:
docs.dhtmlx.com/doku.php?id=dhtm … tcolumnids

Thanks for the help, I tried it, now my code is this:

function buildInterface(){
    //entire code for interface init will go here
    myGrid = new dhtmlXGridObject("mygrid");
    myGrid.setImagePath("../static/js/Codebase/imgs/");
    myGrid.setHeader("Marca,Descrizione,U.m.,Prezzo");
    myGrid.setColumnIds('marca,descrizione,idum,prezzo,tid');
    myGrid.setInitWidths("200,*,150,150");
    myGrid.setColAlign("right,right,right,left");
    myGrid.setSkin("light");
    myGrid.init();
    myGrid.load("aeldati","js");
}
dhtmlxEvent(window,"load", buildInterface);

But the request to the server continues to be:
GET /aeldati
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Status: 200 OK. /aeldati
Obviously, the server response is HTML and the grid does not work.
I’m sad because it really is a nice grid.
Greetings Paolo

We have tested the code snippet that provide - it works correctly. Could you attach a complete demo ? (please use static js,html or other file instead server-side scripts)

  • I enclose the details of the request and response.
  • I enclose the page aeldati in static HTML

When you have tested my code which was the request to the server?
Thanks for your cooperation Regards Paolo
AeldatiHtml.tar.gz (92.5 KB)

For all ajax operations, the Accept line of request will be the same, lib doesn’t change it Accept type based on client side loading type ( it is common ajax loading lib, which loads ANY data )

So if you are expecting special Accept type on server side - it will not work in such way.