Flex AdvancedDataGrid自定义排序问题

发布于 2024-10-03 08:39:58 字数 2699 浏览 2 评论 0原文

我有一个高级数据网格,并且正在实现自定义排序。我的 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 技术交流群。

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

发布评论

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

评论(2

甜点 2024-10-10 08:39:58

您应该简单地提供 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.

独行侠 2024-10-10 08:39:58

我明白了!...Robusto 感谢您为我指明了正确的方向。在我的例子中,您的建议的问题是我正在从配置文件生成列,因此我可以使这个网格组件可重用。因此:
1.我使用的是labelFunction
2. column.sortCompareFunction = myfunc 回调根本不起作用,正如 Adob​​e API 文档中引用的那样。

然而,正如你所说,我正在编写复杂的代码。我需要添加 gc.compareFunction = myCompare;与以下代码(与上面比较):

protected function setGrouping(columnNames:Array):void{
_groupingColumns = [];

            if (columnNames.length > 0) {
                _groupedData = new GroupingCollection2();

                _grouping = new Grouping();

                for (var i:int=0;i<columnNames.length;i++) {
                    var gc:GroupingField = new GroupingField(columnNames[i]);
                    gc.descending = _sort_direction;

                    gc.compareFunction = myCompare;

                    _groupingColumns.push(gc);

                }
                _groupedData.source = _ds;
                _grouping.fields = _groupingColumns;
                _groupedData.grouping = _grouping
                _groupedData.refresh();
                _data = _groupedData;
            } else {
                _data = _ds;
            }

            setGridColumns();
        }

完成后,我只需监听 AdvancedDataGrid 侦听器中的排序事件并从那里调用 setGrouping([abc]) ,如下所示:

protected function adg1_sortHandler(event:AdvancedDataGridEvent):void
            {
                _sortField = event.dataField;
                if (temp.length == 0) {
                    temp.push(DefaultGroupColumn);
                } 

                setGrouping(temp)
                _sort_direction = !_sort_direction;

我希望这对某人有帮助!
美国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 = [];

            if (columnNames.length > 0) {
                _groupedData = new GroupingCollection2();

                _grouping = new Grouping();

                for (var i:int=0;i<columnNames.length;i++) {
                    var gc:GroupingField = new GroupingField(columnNames[i]);
                    gc.descending = _sort_direction;

                    gc.compareFunction = myCompare;

                    _groupingColumns.push(gc);

                }
                _groupedData.source = _ds;
                _grouping.fields = _groupingColumns;
                _groupedData.grouping = _grouping
                _groupedData.refresh();
                _data = _groupedData;
            } else {
                _data = _ds;
            }

            setGridColumns();
        }

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:

protected function adg1_sortHandler(event:AdvancedDataGridEvent):void
            {
                _sortField = event.dataField;
                if (temp.length == 0) {
                    temp.push(DefaultGroupColumn);
                } 

                setGrouping(temp)
                _sort_direction = !_sort_direction;

I hope this helps someone!
AAP

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