11

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

2
  • There is a fix for this on the way - I will post an answer once this has been released. Commented Oct 14, 2014 at 10:37
  • any word on the answer? Commented Mar 18, 2015 at 20:28

1 Answer 1

12

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

Sign up to request clarification or add additional context in comments.

4 Comments

If it only returns the actual visible rows, it won't do any good. It is unlikely that all 500 rows is visible at the same time.
It returns the whole dataset, I have just checked it: $scope.gridOptions.data.length returns the same value as $scope.gridApi.core.getVisibleRows().length . i.imgur.com/42N6EZA.png
note if you have cellTemplates applied (e.g. 12345 -> 12,345) the data returned with this is the data without that formatting applied
@Jesper is right. When using pagination, getVisibleRows() only returns the rows of the current page

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.