Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4892 closed defect (fixed)

Unable to instantiate the grid with a non-parented node

Reported by: Bryan Forbes Owned by: sorvell
Priority: high Milestone: 1.0
Component: DojoX Grid Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description

Doing this:

var grid = new dojox.Grid({ model: some_model, structure: some_structure }, document.createElement("div"));

or this:

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

results in this error:

Object cannot be created in this context" code: "9

I think this stems from the fact that in VirtualGrid?'s resize code, this.domNode.parentNode is used without first checking that it exists:

line 229:
		}else if(this.domNode.clientHeight <= padBorder.h){
			if(this.domNode.parentNode == document.body){
				this.domNode.style.height = this.defaultHeight;
			}else{
				this.fitTo = "parent";
			}
		}
		if(this.fitTo == "parent"){
			var h = dojo._getContentBox(this.domNode.parentNode).h;
			dojo.marginBox(this.domNode, { h: Math.max(0, h) });
		}

I've tried adding a check for parentNode, but when the grid is shown, the data does not show up. Both of these are very common uses for instantiating a dijit.

Attachments (1)

test_grid_programmatic.2.html (2.9 KB) - added by Bryan Forbes 12 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 12 years ago by Bryan Forbes

Owner: changed from sjmiles to sorvell

Changed 12 years ago by Bryan Forbes

comment:2 Changed 12 years ago by Bryan Forbes

I added a test so you can see exactly what I'm doing (test_grid_programmatic.2.html is the correct attachment... I forgot to select "overwrite attachment of the same name"). I used grid's test_grid.html as a starting point and instead of letting the parser instantiate the grid, I did everything in a dojo.addOnLoad function.

comment:3 Changed 12 years ago by Bryan Forbes

One last note, the test file needs to go in dojox/grid/tests/

comment:4 Changed 12 years ago by sjmiles

I've tried adding a check for parentNode, 
but when the grid is shown, the data does 
not show up.

Adding protection for null parentNode in resize does prevent the exception.

After that, adding

grid.render();

to your onload block makes the data appear.

Grid cannot automatically know when you have finally inserted it's node into the document. It must be prodded with a call to render at that point.

It's not clear from your example if that can be automated in the common uses you mentioned.

comment:5 Changed 12 years ago by sjmiles

Resolution: fixed
Status: newclosed

(In [11308]) Prevent 'resize' logic from executing in Grid node has no parent. Fixes #4892.

comment:6 Changed 12 years ago by sjmiles

(In [11309]) Adding test, refs #4892.

Note: See TracTickets for help on using tickets.