How to access the sorted rows in an Angular UI Grid?

心不动则不痛 提交于 2019-12-10 02:16:07

问题


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.

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]);
});

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.

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...


回答1:


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



来源:https://stackoverflow.com/questions/26273686/how-to-access-the-sorted-rows-in-an-angular-ui-grid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!