<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Saki's Blog &#187; grid</title>
	<atom:link href="http://blog.extjs.eu/tag/grid/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.extjs.eu</link>
	<description>For good of all productive developers</description>
	<lastBuildDate>Sun, 21 Nov 2010 01:36:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Keeping modified records of EditorGridPanel while paging</title>
		<link>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/</link>
		<comments>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 08:59:44 +0000</pubDate>
		<dc:creator>Saki</dc:creator>
				<category><![CDATA[Code Patterns]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[Know-how]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://blog.extjs.eu/?p=498</guid>
		<description><![CDATA[<br/>If you modify records of an editable grid with paging and if you then page-out, your changes are lost. Well, they are not lost in fact unless you have set pruneModifiedRecords:true on the strore. The modifications are still available so we just need to apply them. Here is the code fragment that does it:

var grid [...]]]></description>
			<content:encoded><![CDATA[<br/><p>If you modify records of an editable grid with paging and if you then page-out, your changes are lost. Well, they are not lost in fact unless you have set <code><a target="_blank" href="http://www.extjs.com/deploy/dev/docs/?class=Ext.data.Store&#038;member=pruneModifiedRecords">pruneModifiedRecords:true</a></code> on the strore. The modifications are still available so we just need to apply them. Here is the code fragment that does it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> grid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">grid</span>.<span style="color: #660066;">EditorGridPanel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    store<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">new</span> Ext.<span style="color: #660066;">data</span>.<span style="color: #660066;">Store</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
         listeners<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>
            load<span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span>scope<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> fn<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>store<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #006600; font-style: italic;">// loop through modified records</span>
                <span style="color: #003366; font-weight: bold;">var</span> modified <span style="color: #339933;">=</span> store.<span style="color: #660066;">getModifiedRecords</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> modified.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                    <span style="color: #006600; font-style: italic;">// see if we have a record with same id </span>
                    <span style="color: #006600; font-style: italic;">// and apply changes if yes</span>
                    <span style="color: #003366; font-weight: bold;">var</span> r <span style="color: #339933;">=</span> store.<span style="color: #660066;">getById</span><span style="color: #009900;">&#40;</span>modified<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #003366; font-weight: bold;">var</span> changes <span style="color: #339933;">=</span> modified<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getChanges</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>p <span style="color: #000066; font-weight: bold;">in</span> changes<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>changes.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                                r.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">,</span> changes<span style="color: #009900;">&#91;</span>p<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #009900;">&#125;</span>
                        <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo changes loop</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo modified loop</span>
            <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo load listener</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// eo listeners</span>
&nbsp;
        <span style="color: #006600; font-style: italic;">// rest of store configuration</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// rest of grid configuration</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// eo grid</span></pre></div></div>

<p><b>pruneModifiedRecords must be false (the default) for this to work.</b></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.extjs.eu/patterns/code-patterns/keeping-modified-records-of-editorgridpanel-while-paging/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

