UI Grid get sorted items with pagination
<p>I have checked all stackoverflow posts related to ui-grid <a href="https://stackoverflow.com/questions/26273686/how-to-access-the-sorted-rows-in-an-angular-ui-grid">sorted</a> <a href="https://stackoverflow.com/questions/33432159/angularjs-ui-grid-get-filtered-rows-in-despite-of-pagination">rows</a> without any success so I am opening one more question.</p>

<p><strong>SHORT</strong> : Need a way to get sorted rows following current sorting criteria.</p>

<p>My problem is that I have an instance of UI Grid with pagination and I can not get the sorted data after it was added using a <code>$mdDialog</code> modal. It is shown at the right position in the tabel, but behind, in all objects it is stored the new element is on the last position. </p>

<p>I call the ui-grid instance using a service to keep all stuff in one place:</p>

<pre><code>// Default service for init a ui-grid instance
app.serivce('testService', function(){
  var defaultGridOptions = {
      enableColumnMenus: false,
      enablePaginationControls: true,
      paginationPageSizes: [5],
      multipleSorting: false,
      treeRowHeaderAlwaysVisible: false,
      paginationPageSize: 5,
      enableHorizontalScrollbar: uiGridConstants.scrollbars.NEVER,
      enableVerticalScrollbar: uiGridConstants.scrollbars.NEVER
  };

  // Each columns sort rule
  // Position 0 from columnsOrder sorts position 0 from columnDefs and so on
  var defaultColSort = [{
      sort: { direction: uiGridConstants.ASC, priority: 0 }
  }];

  this.createGridOptions = function (gridData, columnDefs, gridOpts) {
      gridOpts = typeof gridOpts !== 'undefined' ? gridOpts : {};
      var gridOptions = angular.extend({}, defaultGridOptions, gridOpts);

      for(var i = 0; i &lt; defaultColSort.length; i++)
          columnDefs[i] = angular.extend({}, defaultColSort[i], columnDefs[i]);

      gridOptions.data = gridData;
      gridOptions.columnDefs = columnDefs;
      return gridOptions;
  };


  // The metod that should move to the desired page
  this.jumpToGridItem = function(api, entry) {
      var idx = -1;
      var page = 0;
      var sortedData = null;

      // NEED A WAY TO GET SORTED DATA HERE 
      //idx = sortedData.indexOf(entry); -&gt; checks the position of the new added item

      if (idx == -1)
          return false;

      // Calculate the page where the element exists
      page = Math.ceil(idx/api.grid.options.paginationPageSize);

      // Jump to page
      api.pagination.seek(page);
  };
})
</code></pre>

<p>Here is my controller : </p>

<pre><code>app.controller('testController', ['$scope', '$mdDialog', 'testService', function($scope, $mdDialog, testService){
  var columnDefs = [
      {
          field: 'identifier',
          name: 'Identifier'
      }
  ];

  var dummyData = [{ identifier: "Item" }, { identifier: 'Item 1' }, { identifier: "Item 2" }, { identifier: "Item 3" }];

  var gridOptions = $scope.gridOptions = testService.createGridOptions(dummyData, columnDefs);

  gridOptions.onRegisterApi = function (gridApi) {
      $scope.gridApi = gridApi;
  };

  $scope.add = function () {
      $mdDialog.show({
          controller: function($mdDialog) {
            var data = $scope.identifierVal;
            $mdDialog.hide(data);
          },
          templateUrl: 'add.html',
          parent: angular.element(document.body)
      }).then(function (entry) {
          // Data received when the modal is hidden
          $scope.gridOptions.data.push(entry);
          testService.jumpToGridItem($scope.gridApi, entry);
      });
  };

}]);
</code></pre>

<p>Right now I am appending the data with <code>push()</code>, this could be one reason, I think.</p>

<p>The method I have to update is <code>jumpToGridItem</code>, which actually should focus the page where the item was added.</p>

<p>Thank you</p>

<p>PS : Sorry for not posting a plnkr, I will do bit later if it is needed.</p>