Login Register

Programmatic dojox.Grid

I know this is still very early stage, but I'm trying to test out the new Grid and I'm getting errors and I'm not sure if I'm just doing this wrong.

I'm trying to use this code
var grid = new dojox.Grid({model: model, structure: layout}, document.createElement("div"));

I have also tried this
var grid = new dojox.Grid({model: model, structure: layout});

I'm getting this for an error message:
"Object cannot be created in this context"

Can Grid not be created programmatically or am I using the syntax wrong?

try the following

you need to place the grid in the dom, ie in an element that has a parent - so given a "parentContainer" element we can create a gridContainer node and append it to the parent (thereby giving it a parent) and create the grid around the gridContainer.

example:

var parentContainer = dojo.byId("some parent element");

var gridContainer = parentContainer.appendChild(document.createElement("div"));

var grid = new dojox.Grid({
    structure: gridLayout,
    model: model
  },
  gridContainer
);

Grid not appearing

Thanks to the above tip, I am able to create a Grid dynamically.

grid = new dojox.Grid({structure:my_layout,model:model,id:grid},gridContainer);
dojo.connect(container, "resize", grid, function() {grid.resize();});
container.onShow = function() { setTimeout(function(){grid.render()}, 0);};
grid.update();

The HTML looks like this:

I am adding this using dojo.addOnload but the grid is not appearing. I inspected the Gri using Firebug and it looks fine.

Am I missing anything?

Thanks

revised...

This may or may not make a difference, but its worth a shot...
grid = new dojox.Grid({structure:my_layout,model:model,id:grid},gridContainer);
grid.startup();
dojo.connect(container, "resize", grid, "resize"); //no need for the extra anon function...
container.onShow = function() { setTimeout(function(){grid.render()}, 500);}; //see if a longer delay helps...
grid.update();
-Karl

I tried these changes as

I tried these changes as well but it is not working for me. I even increased the delay

While viewing the HTML Content in the Firebug, I am able to see the table headers (structure - "dojoxGrid-master-header") but the data div under "dojoxGrid-master-view" is empty. I am pasting the div content for reference.

Thanks

Sounds like your data is

Sounds like your data is missing, are you sure the data is loading correctly?

-Karl

In the dom inspector of

In the dom inspector of firebug, I can see the model and data. If possible, I can attach the screenshot.

one more thing, I am using

one more thing, I am using the same test data that was used in test_grid.html. Only difference is I am building the widget as per the suggestion given in the forum.

Longshot, and haven't seen

Longshot, and haven't seen enough of your grid definition, but I had to, after the grid constructor statement, add grid.setModel(model); and grid.setStructure(layout);

Redundant, I know, but the data didn't display otherwise.

I just noticed I also had a grid.render() (instead of .update) after the grid.startup(). Not sure it is needed.

It worked

While trying various permutations and combinations, I turned off the parseOnLoad attribute. Also, I fixed the probelm I was facing in getting the JSON array (as expected by the grid - with just the values) through java. With this combination, everything worked.
Sorry for the delay and misleading post.

Thanks

Dojo Grid Programmatically

I am trying out this code...the grid shows up, but it says this.store is null or not an object.
The url is perfectly fine. Any idea why its happening??

var parentContainer = dojo.byId("sampleGrid");

var gridContainer = parentContainer.appendChild(document.createElement("div"));

var mstore = new dojo.data.ItemFileReadStore({jsId: 'jsonStore', url: "dijitTest.txt"});
var data = new dojox.grid.data.DojoData({jsId: 'model', store: mstore, rowsPerPage: 20, query: "{ namespace: '*' }"});
var layout = [fixedColumn,view1];
var grid = new dojox.Grid({
structure: layout,
model: data
},
gridContainer
);

grid.startup();

If, in the Firefox Firebug

If, in the Firefox Firebug extension console, you type the line:

mstore = new dojo.data.ItemFileReadStore({jsId: 'jsonStore', url: "dijitTest.txt"});

does the console show:

Object _arrayOfAllItems=[0] _arrayOfTopLevelItems=[0]

and then type mstore.fetch(), does the console show:

Object store=Object

and then when you click on that line, does it expand to show the store and the data items?

Or alternatively typing again, after the fetch, mstore, does it show:

Object _arrayOfAllItems=[nn] _arrayOfTopLevelItems=[nn]

If you are not seeing something like above, confirming the # of items, or if you are seeing errors, dijitTest.txt is not where expected or it contains data in an unexpected format, or you are also seeing an additional error, "ItemFileReadStore is not a constructor", which probably means the dojo.require("dojo.data.ItemFileReadStore") is missing in your html file.

dojox.grid.data.DojoData constructor

Also note, dojox/grid/_data/model.js the constructor for "dojox.grid.data.DojoData" is "constructor: function(inFields, inData, args)", so you need null values for the first two arguments.

No quotes needed on the "query" in js, and the query should specify the field name I believe, so you would need to have a field called "namespace" in your item data for this to work.

var data = new dojox.grid.data.DojoData(null, null, {jsId: 'model', store: mstore, rowsPerPage: 20, query:{namespace:'*'} });