views:

32

answers:

2

I'm creating a table that displays information from a MySQL database, I'm using foreignkeys all over the place to cross-reference data.

Basically I have a datagrid with a column named 'system.' The system is an int that represents the id of an object in another table. I've used lableFunction to cross-reference the two and rename the column. But now sorting doesn't work, I understand that you have to create a custom sorting function. I have tried cross-referencing the two tables again, but that takes ~30sec to sort 1200 rows. Now I'm just clueless as to what I should try next.

Is there any way to access the columns field label inside the sort function?

public function order(a:Object,b:Object):int
{
    var v1:String = a.sys;
    var v2:String = b.sys;
    if ( v1 < v2 ){
        trace(-1);
        return -1;
    }else if ( v1 > v2 ){
        trace(1);
        return 1;
    }else {
        trace(0);
        return 0;
    }
}

A: 

The way that DataGrids, and other list based classes work is by using itemRenderers. Renderers are only created for the data that is shown on screen. In most cases there is a lot more data in your dataProvider than what is seen on screen.

Trying to sort your data based on something displayed by the dataGrid will most likely not give you the results you want.

But, there is no reason you can't call the same label function on your data objects in the sortFunction.

One way is to use the itemToLabel function of the dataGrid:

var v1:String = dataGrid.itemToLabel(a);
var v2:String = dataGrid.itemToLabel(b);

A second way is to just call the labelFunction explicitly:

var v1:String = labelFunction(a);
var v2:String = = labelFunction(b);

In my experience I have found sorting to be extremely quick, however you're recordset is slightly larger than what I usually load in memory at a single time.

www.Flextras.com
A: 

One way to handle this is to go through the objects you received and add the label as a property on each of them based on the cross-referenced id. Then you can specify your label property to display in your data grid column instead of using a label function. That way you would get sorting as you'd expect rather than having to create your own sort function.

Wade Mueller
I think this is what I'm gonna have to do. I was trying to keep all the data separated, but I don't think thats going to happen. I'll give it a try.
Noah Smith
Thanks for the clairvoyance, things seem to work pretty well that way.Basically, I'm keeping all tables separate in the model (using robotlegs), when ever the table is updated it calls a method to add the crossed-referenced field to the table row. I'm not noticing much (if any) extra lag. So thanks again.
Noah Smith