In this article I will demonstrate how to add expandable and collapsible sections to each grid row using the extjs rowexpander plugin.
EXTJS in XPages series
Here are links to all of the previous articles in this series
- EXTJS in XPages #9 – Infinite scrolling rebooted and reborn – v4.2 BufferedRenderer
- EXTJS in XPages #8 – Selecting data from the grid and opening a document
- EXTJS in XPages #7 – Doing an @Unique(@DbColumn) equivalent in the grid
- EXTJS in XPages #6 – remote sorting using the REST service
- EXTJS in XPages #5 – Infinite scroller
- EXTJS in XPages #4 – Adding a Pager
- EXTJS in XPages #3 – Creating a basic grid from a Custom Control
- EXTJS in XPages #2 – Basic Grid capabilities
- EXTJS in XPages #1 – Starting from scratch (the first grid)
Demonstration
The EXTJS in XPages demonstration database can be found at http://demo.xomino.com/xomino/Extjs.nsf/xGridExpand.xsp
Download
The sample database that will accompany this series is available from the menu in the live demo database from this link – http://demo.xomino.com/xomino/Extjs.nsf
Introduction
Now we have the basics of how to build a grid down I am going to demonstrate some of the cool plugins and features which can be added to the EXTJS grids within our XPages. This article focus on the “rowexpander” plugin which gives us the ability to “expand the row” and format the displayed output.
In the example I have created I have used a normal grid showing 240+ countries and territories in the world. When you click on the row it expands and show the reformatted data fields and the country’s flag.
How does it work?
There are no new code bases to be loaded for this plugin it is “out of the box” so to speak. It really could not be simpler…..
I created a new view “vwCountry” and a new REST service to pump out the data
<xe:restService id="country" pathInfo="country"> <xe:this.service> <xe:viewJsonService defaultColumns="true" viewName="vwCountry" count="10000"></xe:viewJsonService> </xe:this.service> </xe:restService>
And then the grid code to retrieve it is the same as the the bufferedRendered example (with new field names)
The significant part is adding the plugin to the grid and inserting the rendering code – but that is also copy and pastable almost. As you can see from the code below there is a ptype: rowexpander plugin and then within that I use an EXT.XTemplate to show the code which I want to display on the screen while the row is expanded. It is as simple as that.
var grid = Ext.create('Ext.grid.Panel', { renderTo: 'gridHere', frame: true, height: 400, layout: 'fit', title: 'Countries', plugins: [{ ptype: 'rowexpander', rowBodyTpl : new Ext.XTemplate( '<p><b>Country:</b> {Name}</p>', '<p><b>Life Expectancy:</b> {Life}</p><br>', '<p><b>Highest Peak:</b> {HighestPeak}</p>', '<p><img class="flag" src="http://www.worldatlas.com/webimage/flags/countrys/zzzflags/{CountryCode:this.lowerCase}large.gif"/></p>', { lowerCase: function(cc){ return cc.toLowerCase() } }) }],
Conclusion
Once again this shows how quick and simple it is to provide excellent functionality for your users with little to no effort on your part as the developer – and that is really what we all like 🙂
Side note
Originally I used the buffereredRenderer on this grid but there appears to be a display issue (v4.2) which has been reported and tracked with Sencha. I removed the bufferedRenderer and it worked fine.
Incredibly cool piece of functionality!