Flex - 按行标签对数据网格列进行排序

发布于 2024-09-14 18:58:05 字数 630 浏览 3 评论 0原文

我正在创建一个表来显示来自 MySQL 数据库的信息,我在各处使用外键来交叉引用数据。

基本上我有一个数据网格,其中有一列名为“系统”。该系统是一个int,表示另一个表中对象的id。我使用 lableFunction 交叉引用两者并重命名该列。但现在排序不起作用,我知道你必须创建一个自定义排序函数。我尝试再次交叉引用这两个表,但这需要大约 30 秒才能对 1200 行进行排序。现在我只是不知道下一步应该尝试什么。

有什么方法可以访问排序函数中的列字段标签吗? <代码>

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;
    }
}

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;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月下伊人醉 2024-09-21 18:58:05

处理此问题的一种方法是遍历您收到的对象,并根据交叉引用的 ID 将标签添加为每个对象的属性。然后,您可以指定要在数据网格列中显示的标签属性,而不是使用标签函数。这样您就可以按照预期进行排序,而不必创建自己的排序函数。

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.

無心 2024-09-21 18:58:05

DataGrid 和其他基于列表的类的工作方式是使用 itemRenderers。渲染器仅为屏幕上显示的数据创建。在大多数情况下,dataProvider 中的数据比屏幕上看到的数据多得多。

尝试根据 dataGrid 显示的内容对数据进行排序很可能不会给您想要的结果。

但是,您没有理由不能在 sortFunction 中的数据对象上调用相同的标签函数。

一种方法是使用 dataGrid 的 itemToLabel 函数:

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

第二种方法是显式调用 labelFunction:

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

根据我的经验,我发现排序非常快,但是您的记录集比我通常在内存中加载的记录集稍大在一次。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文