Home arrow JavaScript arrow Page 2 - EXT JS: the Paging Toolbar and Live Data
JAVASCRIPT

EXT JS: the Paging Toolbar and Live Data


Thanks for joining me in part three of the EXT-JS GridPanel tutorial series. In part two of the series we covered the basic mechanics of getting the data into our JsonStore and displaying it in the grid. We looked both at the server-side PHP and the client-side JavaScript required for achieving this.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 9
August 03, 2009
TABLE OF CONTENTS:
  1. · EXT JS: the Paging Toolbar and Live Data
  2. · Pagination
  3. · Even More PHP
  4. · Summary

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
EXT JS: the Paging Toolbar and Live Data - Pagination
(Page 2 of 4 )

Let’s add the code needed for invoking and creating the PagingToolbar to the underlying page first of all. Open the gridExample.html file in your text editor and change the Ext.grid.GridPanel constructor function in the final <script> block so that it appears as follows:


//define the grid

var grid = new Ext.grid.GridPanel({

el:"productGrid",

width:700,

height:500,

title:"Products",

store:dataStore,

cm:cm,

loadMask:true,

bbar: new Ext.PagingToolbar({

store:dataStore,

displayInfo:true,

displayMessage:"Displaying Products {0} - {1} of {2}"

})

});


The bbar property of the GridPanel allows us to specify properties for a toolbar that is appended to the bottom of the grid. In this example we’re using the PagingToolbar control, but we could instead provide our own paging template or a simple row of buttons (EXT-JS Buttons of course) instead.

We’ve used only three of the many available PagingToolbar properties; the store property is mandatory and ties the toolbar to a data store, namely the JsonStore we created in part two of this tutorial. The displayInfo property enables a kind of inline status bar which gives the visitor information about the current and total records in the grid.

We can configure our own custom message to be displayed in the status bar using the displayMessage property. The string we supply to this property has built-in tokenization, which allows us to specify simple tokens ({0}, {1} etc) which represent information from the store. The following screen shot shows how the pagination bar should appear:



As you can see, the toolbar has correctly determined the number of pages required to hold all of our data, and shows the correct number of records. By default, the paging toolbar displays the data in pages of 20 records; however the grid is still displaying all 37 records from the store. This is because the PagingToolbar works directly with the backend logic rather than the local data store. In the same way that the GridPanel passes parameters to the server when remoteSorting is enabled, the PagingToolbar passes parameters to the server to only request data in specific blocks at a time.

We also need to add one more property to the configuration object for the JsonStore object so that it knows what the total number of records in the MySQL database is, as during the initial request we’re only going to be passing back a subset of the data. Change the Ext.data.JsonStore constructor so that it appears thus:


var dataStore = new Ext.data.JsonStore({

url:'productSearch_part3.php',

root:'products',

fields:['title', 'image', 'inStock', 'price', 'category', 'manufacturer'],

remoteSort:true,

totalProperty:'total'

});


The new property that we’ve configured is the totalProperty, which is mapped to the total property in our JSON object. There isn’t a total property in the JSON object yet, but don’t worry, there will be once we have adjusted the PHP(which we’re going to do next).


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials