AutoSortDataGrid: A simple extension to the DataGrid Flex component

! Warning: this post hasn't been updated in over three years and so may contain out of date information.

In a recent post, I highlighted the arse-about-face nature of the way sorting works with the Flex DataGrid component. As one comment put it, it is synonymous with moving your car wheels to set the steering wheel position.

In response to that, I have created a simple extension to the DataGrid component. It is called AutoSortDataGrid and it adds two properties to DataGrid: sortColumn and sortDirection. These simple additions enable one to specify the initial sort state of a datagrid, and no additional code is required on the user’s part.

Building on the examples used in the previous post, to create a table with the colour data previous used, that sorts in a descending fashion on the red column, use the following code:

The component supports both the data being supplied via the MXML and via ActionScript, and the properties can be both set in the MXML or in ActionScript. The following SWF illustrates this in practice. The first table is pure MXML, the second sets the data via ActionScript and the third sets both the properties and data via ActionScript.

The AutoSortDataGrid SWC, source and documentation.

The AutoSortDataGrid SWC, source and documentation, plus the source for the test SWF displayed above.

An on-line copy of the documentation.

2 thoughts on “AutoSortDataGrid: A simple extension to the DataGrid Flex component

  1. Hi David,
    Nice post. Can you please e-mail when when you get a minute? I’d like to suggest a way you can integrate this with the core Flex 3 documentation.

    Best regards,
    Randy Nielsen
    Flex Documentation Manager
    Adobe Systems Incorporated

  2. hi

    is it possible to change the font size in a datagrid for different rows.. For example if row1 has font size12 can we make rwo2 font size 14..

    Not only font size also makin it bold

Comments are closed.