#10872 closed defect (fixed)
dojox.grid.TreeGrid getItem() returns null for three level path
Reported by: | izikz | Owned by: | Bryan Forbes |
---|---|---|---|
Priority: | blocker | Milestone: | 1.5.1 |
Component: | DojoX Grid | Version: | 1.4.0 |
Keywords: | dojox.grid.TreeGri getItem null three level | Cc: | |
Blocked By: | Blocking: |
Description
getItem() does not work properly in dojox.grid.TreeGrid?. For example:
dojox/grid/tests/test_treegrid_model.html
...
var grid2 = new dojox.grid.TreeGrid?({
treeModel: treeModel2,
structure: layout,
defaultOpen: true
}, 'programmatic_grid');
grid2.startup();
dojo.connect(window, "onresize", grid2, "resize");
var item1 = grid2.getItem('0/0'); returns an object
var item2 = grid2.getItem('0/0/0'); returns null
Attachments (1)
Change History (13)
comment:1 Changed 11 years ago by
comment:2 Changed 11 years ago by
Owner: | changed from bryanforbes to Bryan Forbes |
---|
comment:3 Changed 11 years ago by
This error seems to be in getItem from TreeGrid?.js
The existing codes makes the assumption that cf[i] (array with child attribute names) is defined for every level of the path. In most real-life examples I've seen though, we define only one value and stick to it. e.g. cf=children?.
This explains why it fails at level 3 (and later) levels, as soon as it gets an indexOutOfBounds on cf[].
I'm not quite sure what the correct way of solving this is, but the uploaded code will fix the problem if you use only one childrenAttrs in your source.
if(cf){ for(var i = 0; i < idx.length - 1 && itm; i++){ if(cf[0]){ itm = (s.getValues(itm, cf[0])||[])[idx[i + 1]]; }else{ itm = null; } } }
comment:4 Changed 11 years ago by
comment:5 Changed 11 years ago by
I am experiencing this problem as well, another simple test is load dojox/grid/tests/test_treegrid_model.html then select Nairobi and enter this in a debugger: grid2.selection.getSelected(); nothing gets returned, which makes using a tree grid to work with data pretty useless.
comment:6 Changed 10 years ago by
I am also experiencing this problem.
Looking at TreeStoreModel? getChildren, it seems that for a given parent item, all the childrenattrs are used to get children for that item:
// get children of specified item var childItems = []; for (var i = 0; i < this.childrenAttrs.length; i++) { var vals = store.getValues(parentItem, this.childrenAttrs[i]); childItems = childItems.concat(vals); }
So to be consistent in this case would require a search of every children attribute of every possible parent and then for each result search every children attribute. Perhaps only set a final itm value if i is at its final value (ie we are at the end of idx) and search all tree possibilities until that is set.
If the for loop is to be kept as it is then at every level of idx an array of possible parents (or grandparents...) to the desired final item must be carried forward. Perhaps use the Treestoremodel getchildren method if we have a TreeModel??
I dont think the above solution ideas work though as it doesn't make much sense to have two types of children (eg 'children' and 'kids') at each level and only specify one number per level. (eg 1/5/3/4, does that mean we need to find the 1st 'child' and the 1st 'kid' and then inside each of those find the 5th 'child' and the 5th 'kid'?) If cf.length is greater than 1 I think an error should be thrown or a different input to this function should be required. Maybe 1:1/0:5/0:3/1:4 where the number before the colon identifies the childrenAttr to use at that level.
comment:7 Changed 10 years ago by
I've fixed it like this:
if(cf){ for(var i=0; i<idx.length-1; i++) { for(var j=0; j<cf.length; j++) { itm = (s.getValues(itm, cf[j])||[])[idx[i + 1]]; if(itm != null) { break; } } } }
Works fine for me.
comment:9 Changed 10 years ago by
comment:10 Changed 10 years ago by
Milestone: | tbd → 1.5.1 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Correction: the example should be var item2 = grid2.getItem('0/1/0'); returns null