aodz

Flex dataGrid default column sort

Posted on: October 15, 2008


The below example  gives you a hook to sort a  particular column in a datagrid without user input. One can use the below function where ever a datagrid has to have a default sort order on its column(s).  Note : This works with flex 2 datagrid and not with Advanced datagrid in Moxie.

The dataGridDefaultSort functions requires two input items. The dgName which as the variable suggest is the name of the DataGrid and the dgColumn, DataGrid Column, to be sorted by the numbers. column numbering begins with zero.

These input items are used with the DataGridEvent below and is dispatched (excuted). The DataGridEvent has a total of 9 values for successful operation. They are listed below in expanded detail.

1. type:String — The event type; indicates the action that caused the event. This is represented by the dgName input variable. The DataGridEvent.HEADER_RELEASE constant defines the value of the type property of the event object for a headerRelease event, which indicates that the user pressed and released the mouse on a column header
2. bubbles:Boolean (default = false) — Specifies whether the event can bubble up the display list hierarchy.
3. cancelable:Boolean (default = false) — Specifies whether the behavior associated with the event can be prevented.
4. columnIndex:int (default = -1) — The zero-based index of the column where the event occurred. This is represented by the dgColumn input variable.
5. dataField:String (default = null) — The name of the field or property in the data associated with the column.
6. rowIndex:int (default = -1) — The zero-based index of the item in the in the data provider.
7. reason:String (default = null) — The reason for an itemEditEnd event.
8. itemRenderer:IListItemRenderer (default = null) — The item renderer that is being edited or the header renderer that was clicked.
9. localX:Number — Column x-position for replaying columnStretch events.

Call this function anywhere in the program and  use as per above attributes.

private function dataGridDefaultSort(dgName:Object, dgColumn:int):void{
dgName.dispatchEvent(new DataGridEvent(DataGridEvent.HEADER_RELEASE,   false,true,dgColumn,null,0,null,null,0));
}

About these ads

6 Responses to "Flex dataGrid default column sort"

Nice article ,Thank you very much.

Thanks
Asanka

Nice article indeed.
Do you know though how one could specify the ASC or DESC (ascending or descending order) of the sorting?

Thanks,
Valantis

Very nice, this was really helpful. Thanks!

One way is to dispatch the event twice.

To apply a sort programmatically for an AdvancedDataGrid, you can use a similar function:

private function advancedDataGridDefaultSort(dgName:Object, dgColumn:int):void{
dgName.dispatchEvent(new AdvancedDataGridEvent(AdvancedDataGridEvent.SORT, false,true,dgColumn));
}

I have written a sort comparator function for my data grid column. the data grid has 13k rows in all and it takes a lot of time for the items to get sorted. is there a way to improve the performance.
any help in this regards would be helpful.
-thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

I have moved to a different location

check out my new home
Flexout

calendar

October 2008
M T W T F S S
« Sep   Dec »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Blog Stat

  • 82,190 Hop's so far!!!

follow me

Archives

Linkedin Blogger Twitter Youtube Orkut

Top Clicks

  • None

latest flickr photos

deep in the jungle

little umbrella

poor jumbo!

solitude

over the rice paddy!

More Photos

top rated

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: