Home arrow Tricks, Tips, and Help arrow Code and Documentation for Programmers arrow Flex Datagrid persistant Caseless Sorting
Flex Datagrid persistant Caseless Sorting Print E-mail
I've been working on a project with multiple data grids with multiple columns. The users requested two things: when they get the refreshed list from the server they would like the datagrid to keep the sort that was on it prior, they also want the sort to be case insensative. Below is the actionscript class I created to do just this. I haven't done much testing, but if I make some major updates I'll update the code! I also plan to have it hold the last selected item and reselect it after the reload of data as well!

I just extended datagrid, and this is Flex 3.0, I am guessing it will work the same with gumbo, and around the same way with advanced data grid.
package classes.extendedComponents
{
    import mx.collections.Sort;
    import mx.collections.SortField;
    import mx.controls.Alert;
    import mx.controls.DataGrid;
    import mx.controls.dataGridClasses.DataGridColumn;
    import mx.events.DataGridEvent;
    import mx.utils.ObjectUtil;

    public class InsensativeSortHoldingDataGrid extends DataGrid
    {
        public function InsensativeSortHoldingDataGrid()
        {
            super();
        
        }
        override public function set dataProvider(value:Object):void {
            var temp_sort:Sort = null
            if (  (dataProvider != null) && (dataProvider.toString() != "")   ){
                    if (dataProvider.sort != null) {
                        temp_sort = dataProvider.sort
                        //Alert.show(sort.toString())
                    }
                   
                }
            for each (var dgc:DataGridColumn in this.columns){
                dgc.sortCompareFunction = doCaselessSortForField(dgc.dataField)   
            }
           
            super.dataProvider = value
            if (temp_sort != null){
                super.dataProvider.sort = temp_sort
                super.dataProvider.refresh()
            }
        }
 
       public function doCaselessSortForField(field:String):Function
        {
            return function(obj1:Object, obj2:Object):int
            {
                return         ObjectUtil.stringCompare(obj1[field],obj2[field],true);
            }
        }
   
}
 
 
< Prev   Next >

Jibwa Work Samples

Contact Jibwa LLC

Under Construction

Jibwa.com is under construction. Watch out for broken links, missing pages, potholes and bulldozers. We apologize for the temporary inconvenience - Jibwa.com Staff

News and Updates

Flex 4 Pediatrics One

Recently Jibwa LCC published demonstration videos and a new website design for Pediatrics One Clinical Management software built on Flex Flash Builder...
Read More ...

Eclectic Flea Simple Business Site

Using hand written materials and some photos we managed to create a simple site for Tucson's artsy thrift store. The Eclectic Flea ...
Read More ...

Flash Builder 2 Release changes from beta

I am moving from (flex) Flash Builder Beta 2 to Flash Builder Release Stable and keeping notes on changes I've had to make to my code. 1.) mx names...
Read More ...

Radiology Gallery

Jibwa and Tripwirearts have built and  launched a new website with Dr Benjamin Strong. radiologygallery.com for radiology continuing medical educ...
Read More ...