[Dojo-interest] notify grid to fetch from tree with JsonRestStore

85 views
Skip to first unread message

Simon S.

unread,
May 29, 2010, 4:30:55 AM5/29/10
to dojo-i...@mail.dojotoolkit.org

I have a tree and a grid pointing to the same JsonRestStore. What is the best
way to notify the grid to update when the users clicks on a tree node, so
the grid displays the node's children?

My current solution works so so by using an additional
fetchItemByIdentity(), but sometimes the children are only displayed in the
grid after clicking the node twice (async problem?). Furthermore, if
clicking on a node in the tree fetches the children anyway, why not just
notifying the grid that the tree fetched the children, but how?

dojo.connect(this.tree, 'onClick', this, function(item) {
this.showFolderContentInGrid(item);
});

/**
* Displays folder content in grid.
* @param {item} item selected folder
*/
showFolderContentInGrid: function(item) {
var store = this.store;
if (!store.getValue(item, 'dir')) {
return false;
}
var model = this.treeModel;
var grid = this.grid;
var ref;
if (store.hasAttribute(item, 'id')) {
ref = store.getValue(item, 'id');
}
else {
var ref = store.getValue(item, '$ref');
}
store.fetchItemByIdentity({
identity: ref,
onItem: function(item) {
var attr = model.childrenAttrs[0];
var items = store.getValues(item, attr);
grid.setItems(items); // BUG in grid? the very first time this is
called the grid is not refreshed!
},
onError: function(err) {
console.debug('error fetching store data for grid with ', err);
}
});
},
--
View this message in context: http://dojo-toolkit.33424.n3.nabble.com/notify-grid-to-fetch-from-tree-with-JsonRestStore-tp854101p854101.html
Sent from the Dojo Toolkit mailing list archive at Nabble.com.
_______________________________________________
FAQ: http://dojotoolkit.org/support/faq
Book: http://docs.dojocampus.org
Dojo-i...@mail.dojotoolkit.org
http://mail.dojotoolkit.org/mailman/listinfo/dojo-interest

Christopher Barrett

unread,
May 29, 2010, 6:04:20 PM5/29/10
to dojo-i...@mail.dojotoolkit.org
Simon,
I have a application where there are two grids sharing the same
datastore, and I've found that you have call grid.render(); Here is my
code chunk:
dojo.connect(store, "onSet", function(){
console.log("store onSet is being called");
pendingGrid.render();
});

In my case I'm listening for when the store changes, then I update my
second grid. But I experienced the same grid disappearing on every
other click that you are describing. I'm not sure if it's a bug or what.
-Chris

_______________________________________________

Wei CDL Huang

unread,
May 31, 2010, 5:19:37 AM5/31/10
to dojo-i...@mail.dojotoolkit.org, xw...@cn.ibm.com

Chris,

DataGrid is actually listening to the "onSet" event from store, pls see DataGrid._onSet(), did you meet some issues without your own listener?

Since onSet() is item based, it's better to update corresponding row, grid.render() will render the whole view - guess that's reason why your grid disappears on every
click.


Regards!

-Evan

Christopher Barrett

unread,
Jun 1, 2010, 11:03:25 AM6/1/10
to dojo-i...@mail.dojotoolkit.org
Wei,
I have two grids using the same IFWS. The first grid has two editable
fields. When a user finishes editing one of those fields, the second
grid will show the row that was edited. So only rows that had been
edited are showing in the second grid (the desired behavior). But what
was happening is that on the first edit, the second grid would show the
row. But on the second edit, that row would disappear. Then on the 3rd,
all rows would appear, 4th disappear. And so on. The only way I've
found to get it to behave properly is to add grid.render() to the
store's onSet().
-Chris

> ------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages