Implementing Ext JS Custom Paging Toolbars with ColdFusion 9 cfgrid

If you look at Ext JS examples for 3.0 release you will notice a lot of (New) stuff. The 3.0 release includes a bunch of new plugins to the normal Ext grid framework. A couple of these plugins deal with rendering a different type of paging bar.

Note: The demos/samples for ColdFusion 9 will be a bit slow to load due to them being hosted on a cheap VPS server (the best I could do).

Out of the box, the normal ColdFusion 9 cfgrid has the standard Ext JS paging bar. A demo of the ColdFusion 9 cfgrid can be viewed here: ColdFusion 9 CFGRID.

We will now replace the standard paging bar with a Sliding Pager and a Progress Bar Pager in this blog post.

We will first look at the Sliding Pager implementation. A demo of the Sliding Bar Pager can be viewed Here.

   view plainprintabout
 <head>
     <script type="text/javascript" src="js/SlidingPager.js"></script>
     <script type="text/javascript" src="js/SliderTip.js"></script>
     <script>
         function gridSmash()
         {
             //Get Grid Object
             grid = ColdFusion.Grid.getGridObject('usersgrid');                    
             //Get the Column Model
10               cols = grid.getColumnModel();
11               //Set the column model to add Row Numbering
12              configA = cols.config;            
13              newcolumn = new Ext.grid.RowNumberer();            
14              temp = configA.splice(0,0,newcolumn);                        
15              
16              //Destroy and Eliminate the current paging toolbar            
17              grid.getBottomToolbar().destroy();
18              
19              //The new paging toolbar
20              var bbar2 = new Ext.PagingToolbar({
21                  renderTo: grid.bbar, //We render it to the current grid's bottom bar
22           pageSize: 25,//Pagesize set
23           store: grid.getStore(),//Grid's store set
24           displayInfo: true,//Display the records information
25           plugins: new Ext.ux.SlidingPager()//The plugin that will render the toolbar
26           });
27              
28              grid.syncSize();//Sync to size up everything properly again
29                          
30          }
31          
32      </script>
33  </head>
34  
35  <body>
36      <div align="center">
37          <cfform>
38              <cfgrid title="Users" name="usersgrid" pagesize="25" format="html" colheaderbold="true" colheaderfont="Verdana" colheaderfontsize="90%"
39                  align="middle" colheaderalign="center" collapsible="true" selectOnLoad="false"
40                  font="Verdana" fontsize="90%" striperows="true" striperowcolor="##F0FAFF"
41                  bind="cfc:Users.getUsers({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">

42                  
43                  <cfgridcolumn name="FirstName" header="First Name" width="150">
44                  <cfgridcolumn name="LastName" header="Last Name" width="150">
45                  <cfgridcolumn name="UserName" header="User Name" width="150">
46                  <cfgridcolumn name="DisplayName" header="Display Name" width="150">
47                  
48                                      
49              </cfgrid>
50          </cfform>
51      </div>
52      
53      
54      
55      <cfset AjaxOnLoad("gridSmash")>
56  
57  </body>
First we define our normal cfgrid tag. When the page is loaded we call the gridSmash() function. This function does a few things:
  • Add the Row Numbering to the grid
  • Removes the default paging toolbar and replaces it with one defined through Ext.ux.SlidingPager

Similarly, we can implement a Progress Bar Pager by using another plugin. You can view a demo of the Progress Bar Pager on cfgrid Here. The code change involves a simple line change to the plugins parameter.

   view plainprintabout
 <head>
     <script type="text/javascript" src="js/ProgressBarPager.js"></script>
     <script>
         function gridSmash()
         {
             grid = ColdFusion.Grid.getGridObject('usersgrid');                    
              cols = grid.getColumnModel();
             configA = cols.config;            
             newcolumn = new Ext.grid.RowNumberer();            
10              temp = configA.splice(0,0,newcolumn);                        
11              
12              grid.getBottomToolbar().destroy();
13              //The new paging toolbar
14              var bbar2 = new Ext.PagingToolbar({
15                  renderTo: grid.bbar, //We render it to the current grid's bottom bar
16           pageSize: 25,//Pagesize set
17           store: grid.getStore(),//Grid's store set
18           displayInfo: true,//Display the records information
19           plugins: new Ext.ux.ProgressBarPager()//The plugin that will render the toolbar
20           });
21              
22              grid.syncSize();
23                          
24          }
25          
26      </script>
27  </head>

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Bill's Gravatar Getting a server error when I click on the demo links.
# Posted By Bill | 7/29/09 11:14 AM
Kumar Shah's Gravatar I had to move hosts for CF9 beta hosting, the demos should be working now.
# Posted By Kumar Shah | 7/29/09 1:16 PM
Mark's Gravatar Sorry, still can't get to your demo.
# Posted By Mark | 11/5/09 2:50 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.003.  Design based on ARCLITE by: digitalnature