<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Refreshing a data store</title>
	<atom:link href="http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/feed/" rel="self" type="application/rss+xml" />
	<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/</link>
	<description>The definitive resource for all things Dojo: past, present, future.</description>
	<pubDate>Fri, 21 Nov 2008 03:50:43 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: trutwijd</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-239</link>
		<dc:creator>trutwijd</dc:creator>
		<pubDate>Tue, 15 Jul 2008 13:37:28 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-239</guid>
		<description>Sorry I don't have any answers for refreshing a Tree - did talk to one of the Tree dev's and sounded like the above method (looping over _openedItemIds) should have at least worked.  I'll try to look into it some more to see if there is a solution.  The main problem seems to be convincing a tree node not to check its local data cache...  It might be helpful to file an enhancement request on trac.  (bugs.dojotoolkit.org)

P.S. binspaul, datastore.close() function is not yet available, need to wait till dojo 1.2 for that.</description>
		<content:encoded><![CDATA[<p>Sorry I don&#8217;t have any answers for refreshing a Tree - did talk to one of the Tree dev&#8217;s and sounded like the above method (looping over _openedItemIds) should have at least worked.  I&#8217;ll try to look into it some more to see if there is a solution.  The main problem seems to be convincing a tree node not to check its local data cache&#8230;  It might be helpful to file an enhancement request on trac.  (bugs.dojotoolkit.org)</p>
<p>P.S. binspaul, datastore.close() function is not yet available, need to wait till dojo 1.2 for that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: binspaul</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-238</link>
		<dc:creator>binspaul</dc:creator>
		<pubDate>Mon, 14 Jul 2008 11:12:49 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-238</guid>
		<description>Why is there a difference in the store fetched earlier  and the store fetched after ?

console.info("Tree store (before) : ");
console.info(_this.tree.store);

// Create a new store.
newStore = new dojo.data.ItemFileWriteStore({url: 'folders.html?hidValAction=getjsondata', jsId: "newFolderStore"});
newStore.fetch();
_this.tree.store = newStore;
						
console.info("Tree store (after) : ");
console.info(_this.tree.store);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The output obtained is :

Tree store (before) :
Object _arrayOfAllItems=[18] _arrayOfTopLevelItems=[18]

GET ........./folders.html?hidValAction=getjsondata

Tree store (after) :
Object _arrayOfAllItems=[0] _arrayOfTopLevelItems=[0]


Best regards,
Binu Paul</description>
		<content:encoded><![CDATA[<p>Why is there a difference in the store fetched earlier  and the store fetched after ?</p>
<p>console.info(&#8221;Tree store (before) : &#8220;);<br />
console.info(_this.tree.store);</p>
<p>// Create a new store.<br />
newStore = new dojo.data.ItemFileWriteStore({url: &#8216;folders.html?hidValAction=getjsondata&#8217;, jsId: &#8220;newFolderStore&#8221;});<br />
newStore.fetch();<br />
_this.tree.store = newStore;</p>
<p>console.info(&#8221;Tree store (after) : &#8220;);<br />
console.info(_this.tree.store);</p>
<p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
<p>The output obtained is :</p>
<p>Tree store (before) :<br />
Object _arrayOfAllItems=[18] _arrayOfTopLevelItems=[18]</p>
<p>GET &#8230;&#8230;&#8230;/folders.html?hidValAction=getjsondata</p>
<p>Tree store (after) :<br />
Object _arrayOfAllItems=[0] _arrayOfTopLevelItems=[0]</p>
<p>Best regards,<br />
Binu Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: binspaul</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-237</link>
		<dc:creator>binspaul</dc:creator>
		<pubDate>Mon, 14 Jul 2008 09:52:55 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-237</guid>
		<description>For me, the above mentioned methods are not working. The tree is not getting updated.

METHOD 1 :

var _this = this;
newStore = new dojo.data.ItemFileWriteStore({url: 'test.html?hidValAction=getjsondata', jsId: "datStore"});
newStore.fetch();						
_this.tree.model.store.close();
_this.tree.store = newStore;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

METHOD 2 :

var _this = this;

_this.tree.model.store = new dojo.data.ItemFileWriteStore({url: _this.tree.model.store.url});

_this.tree.model.store.fetch();

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The store is getting populated. But it is not getting reflected in the tree.

Best regards,
Binu Paul</description>
		<content:encoded><![CDATA[<p>For me, the above mentioned methods are not working. The tree is not getting updated.</p>
<p>METHOD 1 :</p>
<p>var _this = this;<br />
newStore = new dojo.data.ItemFileWriteStore({url: &#8216;test.html?hidValAction=getjsondata&#8217;, jsId: &#8220;datStore&#8221;});<br />
newStore.fetch();<br />
_this.tree.model.store.close();<br />
_this.tree.store = newStore;</p>
<p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
<p>METHOD 2 :</p>
<p>var _this = this;</p>
<p>_this.tree.model.store = new dojo.data.ItemFileWriteStore({url: _this.tree.model.store.url});</p>
<p>_this.tree.model.store.fetch();</p>
<p>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</p>
<p>The store is getting populated. But it is not getting reflected in the tree.</p>
<p>Best regards,<br />
Binu Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikedef</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-235</link>
		<dc:creator>mikedef</dc:creator>
		<pubDate>Thu, 03 Jul 2008 10:27:08 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-235</guid>
		<description>i tried the following code with my tree and persist was true, but still nothing happens. any other suggestions? i could destroy the old tree any time i need to refresh the data and substitute it with a new one, but this was i have to build all the context menus again as well.

var new_store = new dojo.data.ItemFileReadStore({url: 'poptarts.txt'});
new_store.fetch();
		
var myTree = dijit.byId("tree");

myTree.store = new_store;

dojo.forEach(myTree._openedItemIds, function (item) {
    n = myTree._itemNodeMap(item);
    n.state = "UNCHECKED"
    n.isExpanded = false;
    n.expand();
});</description>
		<content:encoded><![CDATA[<p>i tried the following code with my tree and persist was true, but still nothing happens. any other suggestions? i could destroy the old tree any time i need to refresh the data and substitute it with a new one, but this was i have to build all the context menus again as well.</p>
<p>var new_store = new dojo.data.ItemFileReadStore({url: &#8216;poptarts.txt&#8217;});<br />
new_store.fetch();</p>
<p>var myTree = dijit.byId(&#8221;tree&#8221;);</p>
<p>myTree.store = new_store;</p>
<p>dojo.forEach(myTree._openedItemIds, function (item) {<br />
    n = myTree._itemNodeMap(item);<br />
    n.state = &#8220;UNCHECKED&#8221;<br />
    n.isExpanded = false;<br />
    n.expand();<br />
});</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikedef</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-234</link>
		<dc:creator>mikedef</dc:creator>
		<pubDate>Tue, 01 Jul 2008 17:10:02 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-234</guid>
		<description>thanks for the advise. i will take a look at it when i got some time left</description>
		<content:encoded><![CDATA[<p>thanks for the advise. i will take a look at it when i got some time left</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: trutwijd</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-233</link>
		<dc:creator>trutwijd</dc:creator>
		<pubDate>Mon, 30 Jun 2008 15:10:04 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-233</guid>
		<description>Sorry - better code formatting:

&lt;pre class="javascript"&gt;
foreach myTree.getExpanededNodes as n
   n.state = "UNCHECKED"
   n.isExpanded = false
   n.expand()
&lt;/pre&gt;

and

&lt;pre class="javascript"&gt;
dojo.forEach(myTree._openedItemIds, function (item) {
   n = myTree._itemNodeMap(item);
   n.state = "UNCHECKED"
   n.isExpanded = false;
   n.expand();
});
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Sorry - better code formatting:</p>
<pre class="javascript">
foreach myTree.getExpanededNodes as n
   n.state = "UNCHECKED"
   n.isExpanded = false
   n.expand()
</pre>
<p>and</p>
<pre class="javascript">
dojo.forEach(myTree._openedItemIds, function (item) {
   n = myTree._itemNodeMap(item);
   n.state = "UNCHECKED"
   n.isExpanded = false;
   n.expand();
});
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: trutwijd</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-232</link>
		<dc:creator>trutwijd</dc:creator>
		<pubDate>Mon, 30 Jun 2008 15:08:30 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-232</guid>
		<description>Hmm - looking over the tree source it appears that each TreeNode maintains its own "state".  If a node has been expanded and you collapse it and re-expand it it will not query the data model on the second expand as the TreeNode considers its children as already having been loaded.  It would be possible if you could easily find a way to do this (psuedocode):

&lt;code javascript&gt;
foreach myTree.getExpanededNodes as n
   n.state = "UNCHECKED"
   n.isExpanded = false
   n.expand()
&lt;/code&gt;

Basically for each node in the tree that is already expanded, set its state to UNCHECKED and call the code to re-expand the nodes.  By having the state as UNCHECKED it will hit the updated data store instead of in-memory cache.

You can try this, but it only works if persist=true is set on your tree:

&lt;code javascript&gt;
dojo.forEach(myTree._openedItemIds, function (item) {
   n = myTree._itemNodeMap(item);
   n.state = "UNCHECKED"
   n.isExpanded = false;
   n.expand();
});
&lt;/code&gt;

Note - the above is untested.  persist=true is needed because it is the only way that myTree._openedItemIds is maintained.  I'm checking with the dev's to see if there's a better way.

Hope that helps,

Josh</description>
		<content:encoded><![CDATA[<p>Hmm - looking over the tree source it appears that each TreeNode maintains its own &#8220;state&#8221;.  If a node has been expanded and you collapse it and re-expand it it will not query the data model on the second expand as the TreeNode considers its children as already having been loaded.  It would be possible if you could easily find a way to do this (psuedocode):</p>
<p><code javascript><br />
foreach myTree.getExpanededNodes as n<br />
   n.state = "UNCHECKED"<br />
   n.isExpanded = false<br />
   n.expand()<br />
</code></p>
<p>Basically for each node in the tree that is already expanded, set its state to UNCHECKED and call the code to re-expand the nodes.  By having the state as UNCHECKED it will hit the updated data store instead of in-memory cache.</p>
<p>You can try this, but it only works if persist=true is set on your tree:</p>
<p><code javascript><br />
dojo.forEach(myTree._openedItemIds, function (item) {<br />
   n = myTree._itemNodeMap(item);<br />
   n.state = "UNCHECKED"<br />
   n.isExpanded = false;<br />
   n.expand();<br />
});<br />
</code></p>
<p>Note - the above is untested.  persist=true is needed because it is the only way that myTree._openedItemIds is maintained.  I&#8217;m checking with the dev&#8217;s to see if there&#8217;s a better way.</p>
<p>Hope that helps,</p>
<p>Josh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mikedef</title>
		<link>http://dojocampus.org/content/2008/06/04/refreshing-a-data-store/#comment-231</link>
		<dc:creator>mikedef</dc:creator>
		<pubDate>Mon, 30 Jun 2008 13:03:28 +0000</pubDate>
		<guid isPermaLink="false">http://dojocampus.org/content/?p=130#comment-231</guid>
		<description>this isnt realy working with trees. i tried it by creaing a new store for the treeModel but the tree wasn't updated at all. any hints?</description>
		<content:encoded><![CDATA[<p>this isnt realy working with trees. i tried it by creaing a new store for the treeModel but the tree wasn&#8217;t updated at all. any hints?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
