Login Register

Grid & ItemFileReadStore - Using modified JSON format

Hello,

I am currently in the process of trying to implement a grid using a JSON store. I have successfully done this with a JSON file that followed the ItemFileReadStore.js requirements of using an items array. I have recently been trying to figure out how best to use a custom JSON store hierarchy with my grid. The store looks like the following:

{ 
      	"top": [ 
               {"id":1, "name": "Name1", "width":2, 
                    "first":[	
                            {"card":1, "circuit":7},
                            {"card":1, "circuit":8} 
                        ], 
                    "second":	[	
                            {"card":2, "circuit":1, "in":1, "func":0}
                        ] 
                },
                {"id":2, "name": "Name2", "width":1, 
                    "first":[	
                            {"card":1, "circuit":4}
                        ], 
                    "second":	[	
                            {"card":2, "circuit":2, "in":1, "func":1},
                            {"card":2, "circuit":3, "in":1, "func":2},
                            {"card":2, "circuit":4, "in":1, "func":3},
                            {"card":2, "circuit":5, "in":1, "func":4},
                            {"card":2, "circuit":6, "in":1, "func":5},
                            {"card":2, "circuit":7, "in":1, "func":6}
                        ] 
                }

            ] 
}

I have found the following post which looks like it may be what I want to do but I am too new to JS to really have any clue what needs to go in the rawdata section at the bottom.

http://www.dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/ma...

Right now I can simply change the ItemFileReadStore.js file to use src instead of items ~line 450 this._arrayOfTopLevelItems = dataObject.top; And by doing do I can access the id, name and width fields but none of the first or second arrays or items within these arrays. I have used firebug to debug the code and can see that it is reading all fields of the JSON storage file however I am not sure how to access them or if more modifications are needed.

I was hoping I could just modify my layout view for the grid using dot notation but that doesn't work to access the secondary arrays.

var simple_top_view = {
				cells: [
					[{field: "id", name: 'ID', width: "3em"},
					{field: "name", name: 'Name', width: "7em"},
					{field: "width", name: 'Width', width: "5em"},
					{field: "first[0].card", name: 'Card#', width: "4em"},
					{field: "second[0].circuit", name: 'Circuit#', width: "5em"}]
					]};

If I use just card or just circuit it doesn't work either (not even incorrect data just ?'s).

So the question does anyone have some helpful hints on how to tackle this problem, I have very limited JS experience which is probably making this much harder to accomplish. This is essentially what I would like to see in the end on the grid:

ID | NAME | WIDTH | FIRST | CARD | CIRCUIT | SECOND | CARD | CIRCUIT | IN | FUNC |
----------------------------------------------------------------------------------
1  | Nam1 |  2    |   1   |   1  |    7    |    1   |   2  |    1    |  0 |   0  |
   |      |       |   2   |   1  |    8    |        |      |         |    |      |
----------------------------------------------------------------------------------
2  | Nam2 |  1    |   1   |   1  |    4    |    1   |   2  |    2    |  1 |  1   |
   |      |       |       |      |         |    2   |   2  |    3    |  1 |  2   |
   |      |       |       |      |         |    3   |   2  |    4    |  1 |  3   |
   |      |       |       |      |         |    4   |   2  |    5    |  1 |  4   |
   |      |       |       |      |         |    5   |   2  |    6    |  1 |  5   |

Hopefully the above table is readable :-)

Thank you all for your help and time, it is much appreciated.
-Alex

Grid and Stores

We discussed a similar issue recently: Getting grid to work with dojo.data.

If there are objects (or arrays) in the data that you're feeding to ItemFileReadStore, the grid doesn't render, because the DojoData-model was not able to fetch data from the store. To get at least something (strings, numbers; not objects or arrays) shown you can try replacing ItemFileReadStore with dojox.data.QueryReadStore - it seems to work with the grid and with this kind of data.

To get the data rendered as you want, you'd better turn this tree-like data into fully tabular format on the server side. You could also try simplifying it a bit: just turn the arrays on server side into strings, where you have separated them onto different lines by inserting "<br>" in between the items.

Changing Dojo Code

I was thinking of actually tackling the itemfilereadstore.js file and make it read and understand the hierarchy I am requiring. However from the sounds of it, the dojoData-model is what would need to be changed instead. My question is that which one actually can't understand the architecture I need it to?

Thank you Maine for the answer previously,

Alexander Block

Store abstraction not necessary

You might want to consider doing it without a store. This level of abstraction is not necessary for the grid - the model alone can serve the grid. So, unless you're planning to use the same data to populate a tree or a combobox, you should probably pick dojox.grid.data.Table and build your solution on top of that one.