我有一个高级数据网格,我正在实现自定义排序。我的 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播放器很可能会崩溃。
我猜某处有内存泄漏,但我无法找到它。
如果有人需要完整的代码,我很乐意提供它..
非常感谢所有帮助