Making RowEditor use your column renderers
The RowEditor plugin is one of my favourite Ext JS components. It basically allows any row on a gri
The RowEditor plugin was recently added to the ExtJS examples page. It works a lot like a normal Grid Editor, except you can edit several fields on a given row at once before saving.
This neatly solves the problem of adding a new row to an editor grid, entering data into the first field and finding it save itself straight away, which is rarely desired. In this fashion we can provide full CRUD for simple models in a single page.
You'll need to get a copy of the javascript, css and images from the server. This is a bit of a pain. If you still have the ExtJS SDK around you can find these in the examples folder, if not you can get each file as follows:
Grab the plugin JS file below and put it where you usually put your .js files: http://www.extjs.com/deploy/dev/examples/ux/RowEditor.js
This needs to go with your other stylesheets, usually in a directory called 'css': http://www.extjs.com/deploy/dev/examples/ux/css/RowEditor.css
Download these two images and put them into your existing 'images' folder (the same place the other ExtJS images live): http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-bg.gif http://www.extjs.com/deploy/dev/examples/ux/images/row-editor-btns.gif
Include the .js and .css files on your page and you should be ready to go.
RowEditor is a normal grid plugin, so you'll need to instantiate it and add to your grid's 'plugins' property. You also need to define what type of Editor is available (if any) on each column:
RowEditor defines a few events, the most useful one being 'afteredit'. Its signature looks like this:
All you need to do is listen to that event on your RowEditor and save your model object appropriately. First though, we'll define the Ext.data.Record that we're using in this grid's store:
And now the afteredit listener itself
The code above simply takes the changes object (which is just key: value object with all the changed fields) and issues a request to your server backend. 'record.phantom' returns true if this record does not yet exist on the server - we use this information above to specify whether we're POSTing to /users or PUTing to /users/123, in line with normal RESTful practices.
The example above allows for editing an existing record, but how do we add a new one? Like this:
Pretty simple stuff - we've just added a toolbar with a button which, when clicked, creates a new User record, inserts it at the top of the grid and focusses the RowEditor on it.
Although not documented, the plugin has a few configuration options:
If you want to customise other elements of the RowEditor you probably can, but you'll need to take a look at the source (it's not scary).
RowEditor is a really nice component which can provide an intuitive interface and save you writing a lot of CRUD code. It is best employed on grids with only a few columns - for models with lots of data fields you're better off with a full FormPanel.
I'd be pretty happy to see this included in the default ExtJS distribution, as I find myself returning to it frequently.
To further enhance your understanding of ExtJS grid functionalities, consider reading Making RowEditor use your column renderers, which offers a practical guide on improving data rendering within the RowEditor plugin. Additionally, explore Ext.ux.Exporter - export any Grid to Excel or CSV for insights on exporting grid data in various formats, or delve into ExtJS grid page size - letting the user decide to learn about enhancing user interaction with grid paging.
The RowEditor plugin is one of my favourite Ext JS components. It basically allows any row on a gri
Sometimes you'll be using a Paging Toolbar on a grid and need to give the user the ability to change