<?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>Ed Spencer &#187; paging</title>
	<atom:link href="http://edspencer.net/tag/paging/feed" rel="self" type="application/rss+xml" />
	<link>http://edspencer.net</link>
	<description>A Sencha Architect</description>
	<lastBuildDate>Sat, 11 Feb 2012 09:20:06 +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>ExtJS grid page size &#8211; letting the user decide</title>
		<link>http://edspencer.net/2009/07/extjs-grid-page-size-letting-user.html</link>
		<comments>http://edspencer.net/2009/07/extjs-grid-page-size-letting-user.html#comments</comments>
		<pubDate>Tue, 28 Jul 2009 07:28:00 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[extjs]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[paging]]></category>

		<guid isPermaLink="false">http://192.168.2.15/Projects/wordpress/?p=36</guid>
		<description><![CDATA[<p>Sometimes you&#8217;ll be using a Paging Toolbar on a grid and need to give the user the ability to change the number of records per page. One way of doing this is by adding a combobox to the toolbar:</p>
<pre class="brush: jscript;">
var combo = new Ext.form.ComboBox({
  name : 'perpage',
  width: 40,
  store: new Ext.data.ArrayStore({
    fields: ['id'],
    data  : [
      ['15'],
      ['25'],
      ['50']
    ]
  }),
  mode : 'local',
  value: '15',

  listWidth     : 40,
  triggerAction : 'all',
  displayField  : 'id',
  valueField    : 'id',
  editable      : false,
  forceSelection: true
});
</pre>
<p>We&#8217;ve set up a simple combo box which allows the user to choose between 15, 25 and 50 records per page. Now let&#8217;s set up a Paging Toolbar, and a listener to take action when the user changes the selection in the combo box:</p>
<pre class="brush: jscript;">
var bbar = new Ext.PagingToolbar({
  store:       store, //the store you use in your grid
  displayInfo: true,
  items   :    [
    '-',
    'Per Page: ',
    combo
  ]
});

combo.on('select', function(combo, record) {
  bbar.pageSize = parseInt(record.get('id'), 10);
  bbar.doLoad(bbar.cursor);
}, this);
</pre>
<p>Finally we&#8217;ll roll it all together into a Grid:</p>
<pre class="brush: jscript;">
var grid = new Ext.grid.GridPanel({
  //your grid setup here...

  bbar: bbar
});
</pre>
<p>If the user needs to be able to enter her own page size, replace the ComboBox with an Ext.form.NumberField, and attach the event listener to the field&#8217;s &#8216;keypress&#8217; event.</p>
]]></description>
			<content:encoded><![CDATA[<p>Sometimes you&#8217;ll be using a Paging Toolbar on a grid and need to give the user the ability to change the number of records per page. One way of doing this is by adding a combobox to the toolbar:</p>
<pre class="brush: jscript;">
var combo = new Ext.form.ComboBox({
  name : 'perpage',
  width: 40,
  store: new Ext.data.ArrayStore({
    fields: ['id'],
    data  : [
      ['15'],
      ['25'],
      ['50']
    ]
  }),
  mode : 'local',
  value: '15',

  listWidth     : 40,
  triggerAction : 'all',
  displayField  : 'id',
  valueField    : 'id',
  editable      : false,
  forceSelection: true
});
</pre>
<p>We&#8217;ve set up a simple combo box which allows the user to choose between 15, 25 and 50 records per page. Now let&#8217;s set up a Paging Toolbar, and a listener to take action when the user changes the selection in the combo box:</p>
<pre class="brush: jscript;">
var bbar = new Ext.PagingToolbar({
  store:       store, //the store you use in your grid
  displayInfo: true,
  items   :    [
    '-',
    'Per Page: ',
    combo
  ]
});

combo.on('select', function(combo, record) {
  bbar.pageSize = parseInt(record.get('id'), 10);
  bbar.doLoad(bbar.cursor);
}, this);
</pre>
<p>Finally we&#8217;ll roll it all together into a Grid:</p>
<pre class="brush: jscript;">
var grid = new Ext.grid.GridPanel({
  //your grid setup here...

  bbar: bbar
});
</pre>
<p>If the user needs to be able to enter her own page size, replace the ComboBox with an Ext.form.NumberField, and attach the event listener to the field&#8217;s &#8216;keypress&#8217; event.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2009/07/extjs-grid-page-size-letting-user.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Getting EXT PagingToolbars to save state</title>
		<link>http://edspencer.net/2008/04/getting-ext-pagingtoolbars-to-save.html</link>
		<comments>http://edspencer.net/2008/04/getting-ext-pagingtoolbars-to-save.html#comments</comments>
		<pubDate>Sat, 12 Apr 2008 16:18:00 +0000</pubDate>
		<dc:creator>Ed Spencer</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[ext]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[paging]]></category>

		<guid isPermaLink="false">http://192.168.2.15/Projects/wordpress/?p=2</guid>
		<description><![CDATA[<p>A problem that has recently had me pulling my hair out is how to save state in an EXT PagingToolbar.</p>
<p>Ext makes it easy to save the state of most of its components &#8211; by default it does this by setting a cookie with the relevant configuration info, then just reading it back when you load the component again.  I&#8217;ve been using it to save the state of a few EXT grids I&#8217;ve been using on a recent project, this saves config such as which columns you have visible, which column you&#8217;re sorting by, and how the columns are ordered.</p>
<p>That works great, and is trivial to implement &#8211; just set your provider (see <a href="http://extjs.com/deploy/dev/docs/?class=Ext.state.CookieProvider">http://extjs.com/deploy/dev/docs/?class=Ext.state.CookieProvider</a>) and be sure to give your grid an id in its config &#8211; this is used as the key in the state provider and needs to be unique for each component.</p>
<p>The problem comes when you&#8217;re using a paging toolbar though, as this does not save state, so every time you view the grid you&#8217;re back to page 1.  You can add state behaviour to the paginator by piggybacking the grid&#8217;s state store, here&#8217;s how it&#8217;s done:</p>
<pre class="brush: jscript;">
Ext.PagingToolbar.override({
  init : function (grid) {
    this.grid = grid;
    this.grid.on(&quot;beforestatesave&quot;, this.saveState, this);
    Ext.util.Observable.capture(grid.store, this.onStateChange, this);
  },
  saveState : function(grid, state) {
    state.start = grid.store.lastOptions.params.start;
  },
  onStateChange : function(ev, store, records, options) {
    if (ev == &quot;load&quot;) {this.grid.saveState(); };
  }
});
</pre>
<p>Basically we&#8217;re intercepting the attached Grid&#8217;s saveState() event and appending the current start value as stored in the Grid&#8217;s DataStore (e.g. if you&#8217;re looking at page 3 with 25 rows per page then start = 50).  If you examine the contents of your state provider using Firebug (Ext.state.Manager.getProvider().state, then look for the key that matches the id of your grid), you&#8217;ll see that there is now a record for &#8217;start&#8217;, which grabbed the correct value from the Grid&#8217;s store.</p>
<p>All you need to do then is retrieve that value from the state provider and load your store accordingly:</p>
<pre class="brush: jscript;">
store = new Ext.data.Store({... your store config ...});

grid = new Ext.grid.GridPanel({
  id: 'unique_grid_id',
  store: store,
  ... other grid config ...
});

//shorthand way of retrieving state information
var state = Ext.state.Manager.getProvider();

var start = state.get(options.id).start || 0);
store.load({params: {start: start, limit: 25}});
</pre>
<p>If the start value for this grid has never been set it&#8217;ll default to zero &#8211; e.g. the first page.  Next time you come back to this grid it&#8217;ll take you right back to where you were, including all column setup and sorting behaviour you have specified.</p>
]]></description>
			<content:encoded><![CDATA[<p>A problem that has recently had me pulling my hair out is how to save state in an EXT PagingToolbar.</p>
<p>Ext makes it easy to save the state of most of its components &#8211; by default it does this by setting a cookie with the relevant configuration info, then just reading it back when you load the component again.  I&#8217;ve been using it to save the state of a few EXT grids I&#8217;ve been using on a recent project, this saves config such as which columns you have visible, which column you&#8217;re sorting by, and how the columns are ordered.</p>
<p>That works great, and is trivial to implement &#8211; just set your provider (see <a href="http://extjs.com/deploy/dev/docs/?class=Ext.state.CookieProvider">http://extjs.com/deploy/dev/docs/?class=Ext.state.CookieProvider</a>) and be sure to give your grid an id in its config &#8211; this is used as the key in the state provider and needs to be unique for each component.</p>
<p>The problem comes when you&#8217;re using a paging toolbar though, as this does not save state, so every time you view the grid you&#8217;re back to page 1.  You can add state behaviour to the paginator by piggybacking the grid&#8217;s state store, here&#8217;s how it&#8217;s done:</p>
<pre class="brush: jscript;">
Ext.PagingToolbar.override({
  init : function (grid) {
    this.grid = grid;
    this.grid.on(&quot;beforestatesave&quot;, this.saveState, this);
    Ext.util.Observable.capture(grid.store, this.onStateChange, this);
  },
  saveState : function(grid, state) {
    state.start = grid.store.lastOptions.params.start;
  },
  onStateChange : function(ev, store, records, options) {
    if (ev == &quot;load&quot;) {this.grid.saveState(); };
  }
});
</pre>
<p>Basically we&#8217;re intercepting the attached Grid&#8217;s saveState() event and appending the current start value as stored in the Grid&#8217;s DataStore (e.g. if you&#8217;re looking at page 3 with 25 rows per page then start = 50).  If you examine the contents of your state provider using Firebug (Ext.state.Manager.getProvider().state, then look for the key that matches the id of your grid), you&#8217;ll see that there is now a record for &#8217;start&#8217;, which grabbed the correct value from the Grid&#8217;s store.</p>
<p>All you need to do then is retrieve that value from the state provider and load your store accordingly:</p>
<pre class="brush: jscript;">
store = new Ext.data.Store({... your store config ...});

grid = new Ext.grid.GridPanel({
  id: 'unique_grid_id',
  store: store,
  ... other grid config ...
});

//shorthand way of retrieving state information
var state = Ext.state.Manager.getProvider();

var start = state.get(options.id).start || 0);
store.load({params: {start: start, limit: 25}});
</pre>
<p>If the start value for this grid has never been set it&#8217;ll default to zero &#8211; e.g. the first page.  Next time you come back to this grid it&#8217;ll take you right back to where you were, including all column setup and sorting behaviour you have specified.</p>
]]></content:encoded>
			<wfw:commentRss>http://edspencer.net/2008/04/getting-ext-pagingtoolbars-to-save.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

