HierarchicalCollectionView:一次性排序?

发布于 2024-11-07 06:09:57 字数 595 浏览 1 评论 0原文

我有一个 AdvancedDataGrid,它依赖于 HierarchicalCollectionView 因为它是 dataProvider。我想做的是在首次加载时对数据进行排序,然后禁用排序,以便初始加载后添加的任何内容都不会导致网格再次自动排序。我尝试了这样的事情:

this._myDataProvider = new HierarchicalCollectionView(
                           new HierarchicalData(this._model.rootTasks));

var mySort:Sort = new Sort();                   
mySort.fields = [new SortField("startDate")];

this._tasksDataProvider.sort = taskSorting;
this._tasksDataProvider.refresh();
this._tasksDataProvider.sort = null;

但是将排序设置为 null 只会使数据未排序。我想我要问的是:如何对底层分层数据进行排序,因为似乎设置排序属性将使其保持动态排序。感谢您提供的任何帮助。

I have an AdvancedDataGrid that relies on a HierarchicalCollectionView as it's dataProvider. What I'd like to do is sort the data when it is first loaded, but then disable the sort so that anything that is added after the initial load doesn't cause the grid to auto-sort again. I tried something like this:

this._myDataProvider = new HierarchicalCollectionView(
                           new HierarchicalData(this._model.rootTasks));

var mySort:Sort = new Sort();                   
mySort.fields = [new SortField("startDate")];

this._tasksDataProvider.sort = taskSorting;
this._tasksDataProvider.refresh();
this._tasksDataProvider.sort = null;

But setting the sort to null just leaves the data unsorted. I guess what I'm asking is: how can I sort the underlying hierarchical data since it seems setting the sort property will keep it dynamically sorting. Thanks for any help you can provide.

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

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

发布评论

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

评论(3

甜`诱少女 2024-11-14 06:09:57

就个人而言,当您获取数据时,我会更改排序顺序。它要么在服务器端完成,要么在解析数据时(即在模型中)完成。您可以使用 Array 和 sortOn 进行一次性排序。

Personally, I would change the sort order when you're getting the data. Either it's done on the server side or when you parse the data (ie. in your model). You can do a one time sort using Array with sortOn.

野鹿林 2024-11-14 06:09:57

你可以
1.使用sort函数对原始数据进行排序,
2.克隆内容并将其放入一个新的集合中,不进行排序(小心进行手动克隆),
3.只需使用新收集的数据即可。

you can
1. sort the original data with sort function,
2. clone content and put it to a new collection with no sort (be careful do and make a manual clone),
3. just use the new data collection.

偏爱你一生 2024-11-14 06:09:57

我遇到了同样的问题,直到我意识到使用 Sort 对象进行排序不会改变 Collection 中项目的“物理”顺序,因此当您删除 Sort 时,下一次刷新会将视图恢复为实际的“物理”顺序订购。
与上面类似,我通过以下方式将子集合克隆为排序顺序来解决:

    public static function buildPositionSort():Sort
    {
        var dataSortField:SortField = new SortField();
        dataSortField.name = "position";
        dataSortField.numeric = true;
        dataSortField.descending = false;
        var sort:Sort = new Sort();
        sort.fields = [ dataSortField ];
        return sort;
    }
    /**
     * This method is used to create a clone of ArrayCollection, because sorting does not
     * actually change the physical ordering of the items.
     */
    public static function createSortedArrayCollectionCopy(source:ArrayCollection):ArrayCollection
    {
        var target:ArrayCollection = new ArrayCollection();
        source.sort = buildPositionSort();
        source.refresh();
        for each (var item:Object in source)
        {
            if (item.children != null) item.children = createSortedArrayCollectionCopy(item.children);
            target.addItem(item);
        }
        return target;
    }

I had the same kind of problem until I realized that the sorting with Sort object does not change the "physical" ordering of the items within the Collection, so when you remove the Sort, the next refresh reverts the view to the actual "physical" ordering.
Similarily as stated above, I solved by it by cloning the sub-collections into sorted order this way:

    public static function buildPositionSort():Sort
    {
        var dataSortField:SortField = new SortField();
        dataSortField.name = "position";
        dataSortField.numeric = true;
        dataSortField.descending = false;
        var sort:Sort = new Sort();
        sort.fields = [ dataSortField ];
        return sort;
    }
    /**
     * This method is used to create a clone of ArrayCollection, because sorting does not
     * actually change the physical ordering of the items.
     */
    public static function createSortedArrayCollectionCopy(source:ArrayCollection):ArrayCollection
    {
        var target:ArrayCollection = new ArrayCollection();
        source.sort = buildPositionSort();
        source.refresh();
        for each (var item:Object in source)
        {
            if (item.children != null) item.children = createSortedArrayCollectionCopy(item.children);
            target.addItem(item);
        }
        return target;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文