Flex - 按行标签对数据网格列进行排序
我正在创建一个表来显示来自 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
处理此问题的一种方法是遍历您收到的对象,并根据交叉引用的 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.
DataGrid 和其他基于列表的类的工作方式是使用 itemRenderers。渲染器仅为屏幕上显示的数据创建。在大多数情况下,dataProvider 中的数据比屏幕上看到的数据多得多。
尝试根据 dataGrid 显示的内容对数据进行排序很可能不会给您想要的结果。
但是,您没有理由不能在 sortFunction 中的数据对象上调用相同的标签函数。
一种方法是使用 dataGrid 的 itemToLabel 函数:
第二种方法是显式调用 labelFunction:
根据我的经验,我发现排序非常快,但是您的记录集比我通常在内存中加载的记录集稍大在一次。
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:
A second way is to just call the labelFunction explicitly:
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.