Dojo Data Grid – Part 6: Reordering Columns
Column reordering is a useful feature of a grid. If you provide the user the ability to rearrange the columns, you can create less views and grids in the application. There’s no property built into the dojo data grid to allow the user to reorder the columns, but it’s easy to add with a dojo attribute.
Dojo Data Grid Series
- Part 1: Concepts and Default Features
- Part 2: Creating a REST Service
- Part 3: Creating Your First Grid
- Part 4: Additional Grid Features
- Part 5: Grid Column Features
By default, Dojo Data Grid columns cannot be reordered, but it is an available feature of the dojo grid. All it requires is for the grid to have an attribute of columnReordering set to true. Fortunately, there is a way to add a dojo attribute.
Under All Properties > dojo > dojoAttributes, you can add a dojo attribute, set its name to columnReordering and set it’s value to true.
This is what the attribute looks like in the page source:
<xe:this.dojoAttributes> <xp:dojoAttribute name="columnReordering" value="true"></xp:dojoAttribute> </xe:this.dojoAttributes>
Now, if I want the lastname column to come before the firstname column in my grid, all I have to do is click on the column header and drag it to the left.
And now the order has been changed.
In the next post, I’ll show what is required for sorting the grid and preventing sorting of specific columns or specific sort directions.