Adding a sortcomparefunction to Dynamic Data Grid in flex

Posted by Tom on Stack Overflow See other posts from Stack Overflow or by Tom
Published on 2010-05-28T10:35:08Z Indexed on 2010/05/28 10:41 UTC
Read the original article Hit count: 501

Hi,

I am trying to create a dynamic datagrid in Flex 3, I have a list of columns a list of objects which correspond to datapoints for those columns which I fetch from a url. While the grid works perfectly fine the problem is that sorting on the columns is done in lexical order.

I am aware that this can be fixed by adding a sortcomparefunction to a column, which is not easy for this case. I have tried doing

            var dgc:DataGridColumn = new DataGridColumn(dtf);
            f1[dtf] = function(obj1:Object, obj2:Object):int {
               return Comparators.sortNumeric(obj1[dtf],obj2[dtf]);
            };
            dgc.sortCompareFunction = f1[dtf];`

But the problem is that the function object that I am creating here is being overwritten in every iteration (as I am adding columns) and eventually all the columns will have sorting done only on the last column added.

Suggestions please.

© Stack Overflow or respective owner

Related posts about flex

Related posts about dynamic