如何访问 Angular UI 网格中的排序行? [英] How to access the sorted rows in an Angular UI Grid?

查看:26
本文介绍了如何访问 Angular UI 网格中的排序行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular UI 网格来显示一些数据.启用和初始化排序以及选择单行:

I am using the Angular UI Grid to display some data. Sorting is enabled and initialized as well as selecting a single row:

vm.gridOptions = {
    enableSorting: true,
    enableRowSelection: true,
    multiSelect: false,
    noUnselect: true,
    columnDefs: [
        { name: '#', field: 'ID' },
        { name: 'Name', field: 'CODE', sort: { direction: 'asc', priority: 1 } },
        { name: 'Comment', field: 'DESCR' },
    ],
    data: []
};

我可以选择一行,并且这些行按照配置按名称"列按升序排序.

I am able to select a row and the rows are sorted by the "Name" column in ascending order as configured.

UI Grid Tutorial 210所示,我添加了自动选择第一项的逻辑在我的数据加载并添加到网格之后:

As shown in the UI Grid Tutorial 210, I have added logic to automatically select the first item after my data has been loaded and added to the grid:

datacontext.getAllGcTab(vm.filter).then(function (result) {
    vm.gridOptions.data = result.results;
    vm.gridApi.selection.selectRow(vm.gridOptions.data[0]);
});

但此代码正在选择未排序数据的第一项.我的网格中大约有 500 个项目,数量不多且性能良好,但在这种情况下,所选项目位于该行的某处并且不可见.

But this code is selecting the first item of the unsorted data. There are about 500 items in my grid, which is not much and performs well, but in this case the selected item is somewhere down the line and invisible.

是否有任何选项可以直接访问 UI Grid 的行或排序数据?

Is there any option to directly access the rows or the sorted data of the UI Grid?

我知道外部排序可以解决这个问题,因为那样我会将已经排序的数据分配给网格.但这在我看来像是不必要的开销...

I know that external sorting could solve that problem, because then I would assign the already sorted data to the grid. But this seems to me like an unnecessary overhead...

推荐答案

$scope.gridApi.core.getVisibleRows() 返回当前排序/过滤顺序的行数组.

$scope.gridApi.core.getVisibleRows() returns an array of rows in the current sort/filter order.

这篇关于如何访问 Angular UI 网格中的排序行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆