Flex AdvancedDataGrid自定义排序问题
我有一个高级数据网格,并且正在实现自定义排序。我的 adv.data 网格在每次后续排序时都会减慢......并且如果节点打开,它就会超时。
我的数据如下所示(g = grp on ID)*
ID f_name l_name fld1 fld2
(g)
--------------------------------------
1 A1 B1 xyx xyz
A6 B6 xyx xyz
--------------------------------------
2 A3 B3 xyx xyz
A8 B8 xyx xyz
--------------------------------------
当我对 F_NAME 或 L_NAME 进行排序时,排序 ArrayCollection 应按如下方式排序并显示数据(g = grp on ID)*:
ID f_name l_name fld1 fld2
(g)
-----------------------------------------
1(1) A1 B1 xyx xyz
2(2) A3 B3 xyx xyz
-----------------------------------------
1(3) A6 B6 xyx xyz
2(4) A6 B6 xyx xyz
-----------------------------------------
为此,我使用了一个排序事件,其中如下所示
protected function adg1_headerReleaseHandler(event:AdvancedDataGridEvent):void
{
event.preventDefault();
sort_dir = !sort_dir;
var sort:Sort = new Sort();
sort.fields = [new SortField(event.dataField, true,sort_dir),new SortField('ID', true,sort_dir)]
_ds.sort = sort;
_ds.refresh();
adg1.dataProvider = null;
var previousRegId:int = 0;
var counter:int = 0;
for each (var item:DueInVO in _ds) {
if (previousRegId != item.ID) {
counter++;
previousRegId = item.ID
}
item.uid = counter;
}
/*
var previousRegId:int = 0;
var counter:int = 0;
var csr:IViewCursor = DataSource.createCursor();
while(!csr.afterLast){
if (previousRegId != csr.current.registration_id) {
counter++;
previousRegId = csr.current.registration_id
}
csr.current.uid = counter;
csr.moveNext();
}
*/
setGrouping(['uid']);
//csr = null;
}
,setGrouping 函数如下所示:
protected function setGrouping(columnNames:Array):void{
var _groupingColumns:Array = [];
var gc:GroupingField;
if (columnNames.length > 0) {
var _groupedData:GroupingCollection2 = new GroupingCollection2();
var _grouping:Grouping = new Grouping();
for (var i:int=0;i<columnNames.length;i++) {
gc = new GroupingField(columnNames[i]);
//gc.numeric = true;
//gc.compareFunction = compareFunc;
//gc.groupingFunction = groupFunc;
_groupingColumns.push(gc);
}
_groupedData.source = _ds;
_grouping.fields = _groupingColumns;
_groupedData.grouping = _grouping
_groupedData.refresh();
adg1.dataProvider = _groupedData;
} else {
adg1.dataProvider = _ds;
}
}
但是,每个后续的排序请求需要越来越长的时间才能解决。如上所述,如果分组节点被打开,则Flash播放器崩溃的可能性很大。
我猜测某处存在内存泄漏,但我无法确定它。
如果有人需要完整的代码,我将很乐意提供。
非常感谢所有帮助
I have an advanced datagrid and I am implementing a custom sort. My adv.data grid slows down on each consequent sorting...and if the nodes are opened, it simply times out.
My data looks like the following (g = grp on ID)*
ID f_name l_name fld1 fld2
(g)
--------------------------------------
1 A1 B1 xyx xyz
A6 B6 xyx xyz
--------------------------------------
2 A3 B3 xyx xyz
A8 B8 xyx xyz
--------------------------------------
When I sort on F_NAME or L_NAME the sorting ArrayCollection should sort and show data as follows(g = grp on ID)*:
ID f_name l_name fld1 fld2
(g)
-----------------------------------------
1(1) A1 B1 xyx xyz
2(2) A3 B3 xyx xyz
-----------------------------------------
1(3) A6 B6 xyx xyz
2(4) A6 B6 xyx xyz
-----------------------------------------
To do this I am employing a sort event which looks like the following
protected function adg1_headerReleaseHandler(event:AdvancedDataGridEvent):void
{
event.preventDefault();
sort_dir = !sort_dir;
var sort:Sort = new Sort();
sort.fields = [new SortField(event.dataField, true,sort_dir),new SortField('ID', true,sort_dir)]
_ds.sort = sort;
_ds.refresh();
adg1.dataProvider = null;
var previousRegId:int = 0;
var counter:int = 0;
for each (var item:DueInVO in _ds) {
if (previousRegId != item.ID) {
counter++;
previousRegId = item.ID
}
item.uid = counter;
}
/*
var previousRegId:int = 0;
var counter:int = 0;
var csr:IViewCursor = DataSource.createCursor();
while(!csr.afterLast){
if (previousRegId != csr.current.registration_id) {
counter++;
previousRegId = csr.current.registration_id
}
csr.current.uid = counter;
csr.moveNext();
}
*/
setGrouping(['uid']);
//csr = null;
}
and the setGrouping function looks like the following:
protected function setGrouping(columnNames:Array):void{
var _groupingColumns:Array = [];
var gc:GroupingField;
if (columnNames.length > 0) {
var _groupedData:GroupingCollection2 = new GroupingCollection2();
var _grouping:Grouping = new Grouping();
for (var i:int=0;i<columnNames.length;i++) {
gc = new GroupingField(columnNames[i]);
//gc.numeric = true;
//gc.compareFunction = compareFunc;
//gc.groupingFunction = groupFunc;
_groupingColumns.push(gc);
}
_groupedData.source = _ds;
_grouping.fields = _groupingColumns;
_groupedData.grouping = _grouping
_groupedData.refresh();
adg1.dataProvider = _groupedData;
} else {
adg1.dataProvider = _ds;
}
}
However each consequent request to sort is taking longer and longer to resolve. As stated above, if the nodes of grouping are opned, then there is a high likelyhood that Flash player crashes.
I am guessing there is a mem-leak somewhere but I am not able to put a finger on it.
If anyone requires the full code, I will be happy to provide it..
All help is greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该简单地提供 sortCompareFunction 到您的 ADG 列。您不必捕获标题单击事件等。它已经为你做好了。您所要做的就是指定对特定列的比较将如何进行。
Instead of doing this, you should simply provide a sortCompareFunction to your ADG column. You don't have to capture the header click event and all that. It's already done for you. All you have to do is specify how your comparison for a particular column will play out.
我明白了!...Robusto 感谢您为我指明了正确的方向。在我的例子中,您的建议的问题是我正在从配置文件生成列,因此我可以使这个网格组件可重用。因此:
1.我使用的是labelFunction
2. column.sortCompareFunction = myfunc 回调根本不起作用,正如 Adobe API 文档中引用的那样。
然而,正如你所说,我正在编写复杂的代码。我需要添加 gc.compareFunction = myCompare;与以下代码(与上面比较):
protected function setGrouping(columnNames:Array):void{
_groupingColumns = [];
完成后,我只需监听 AdvancedDataGrid 侦听器中的排序事件并从那里调用 setGrouping([abc]) ,如下所示:
我希望这对某人有帮助!
美国AP协会
I got it!... Robusto thanks for pointing me in somewhat right direction. The problem with your suggestion in my case is that I am generating columns from a config file, so I can make this grid-component reusable. So because of that:
1. I am using a labelFunction
2. column.sortCompareFunction = myfunc callback simply doesn't work as quoted from Adobe API documentation.
However, as you said, I was writing convoluted code. I needed to add gc.compareFunction = myCompare; to the following code (compare from above):
protected function setGrouping(columnNames:Array):void{
_groupingColumns = [];
Once that was done I just had to listen to the sort event in the AdvancedDataGrid listener and call the setGrouping([abc]) from there, as follows:
I hope this helps someone!
AAP