JSON Format Issue

Hello,

We are evaluating this product for use on our company and being new to this I have one issue so far. That is dynamically creating a grid based on data from the DB. Our application is a Java based application that returns a JSON object to the front end. Our JSON object is correct as it has this format:
[
{
1:“a”,
2:“b”,
3:“c”,
4:“d”,
5:“e”
},
{
1:“r”,
2:“s”,
3:“t”,
4:“u”,
5:“v”
}
]
etc… That could have many more records in that format. The columns are the numbers and the rows for each column would be the letters.
We need to be able to create the grid dynamically, including the colunmns.
When we try to create a Grid passing a JSON format as above, we get a java script error that says “data.rows is undefined”. Is that really a requirement? That for a JSON format we need to modify the JSON object to look somethins like I show below:
{
rows:[
{ id:1,
data:[
“a”,
“b”,
“c”,
“d”,
“e”]
}

Do we have to add in the words “rows” and “id” and “data” to get this to work? Or is there a way around this?

Any help will be greatly appreciated.

Thanks,

Luis Esquivel

Do we have to add in the words “rows” and “id” and “data” to get this to work?
Yes, you have to add words “rows”, “id” and “data” to get it work.

Or is there a way around this?
You can create custom JSON format. Please find tutorial here docs.dhtmlx.com/doku.php?id=dhtm … _loading&s[]=custom&s[]=xml#custom_loading_types_creation

Note, each row in grid must have unique id.

Thank you!

Can I have some more examples of JSON formats?

I’m not understanding clearly how we can use a more generics JSON format from a database to fill a grid.

My idea is to have something more generic such as

[
{
“id”: “123”,
“column2”: “valu2”,
“column3”: “valu3”
},{
“id”: “456”,
“column2”: “valu2”,
“column3”: “valu3”
}
]

as that can easily be dumped from our database and the view can be tinkered from the select… (all other config is done from the gfrid itself, obviously)… but i dont need to do any id management outside of the array or anything… I can also just send the entire DB return field-set to the JSON encoder, without needing even to re-parse it…

any ideas about something of the sort?

(I’m also having some issues with grid.parse(myJsonVariable,“json”) using the evaluation copy as i’m getting that a.rows error… I e-mailed sergey about it…

thanks!

Can I have some more examples of JSON formats?
You can find tutorial here docs.dhtmlx.com/doku.php?id=dhtm … _loading&s[]=json&s[]=format#loading_data_from_json
docs.dhtmlx.com/doku.php?id=dhtm … emplates&s[]=json&s[]=format#json_format_details

I’m not understanding clearly how we can use a more generics JSON format from a database to fill a grid.
It not possible to use “generics” JSON format. You should always use “rows”, “id” and “data” tags. As a workaround I can recommend you to use JSONDataConnector which can help you simplify server side operations related dhtmlxGrid. Please find more information here docs.dhtmlx.com/doku.php?id=dhtm … _connector

Can you double-check if datagrid supports jsondataconnector?

I couldnt get it to work initially… I tried again, but from memory the json looking like i said, no id, rows, separate, id was together with each row…

Try to use latest version of dhtmlxConnectors dhtmlx.com/x/download/regula … or_php.zip