How to do client-side pagination with ngGrid?
Asked Answered
T

2

6

If you set the enablePaging options of an ng-grid to true, you enable server-side pagination.

What about client-side one? I could not find any hint on this in the documentation, but I can not imagine that ng-grid does not support client-side paging as well.

Any hint?

Tressietressure answered 28/11, 2013 at 8:46 Comment(0)
R
6

I think the example given on the angular page (http://angular-ui.github.io/ng-grid/) actually shows an example of client-side paging. If you look at the data load that is being called by the sample script (http://angular-ui.github.io/ng-grid/jsonFiles/largeLoad.json), you'll see that its not actually doing any server-side paging... it's coming down as one big file.

Reft answered 5/12, 2013 at 22:27 Comment(2)
If you observe closely, what happens when you click on a next page, it certainly makes an ajax call and apparently it brings the same file over and over.Hopson
404. Answer needs updating.Phosphate
M
0

It might help you!!

The AngularJs code-sample

var app = angular.module('myApp', ['ngGrid']);
app.controller('MyCtrl', function($scope, $http) {
  $scope.filterOptions = {
    filterText: ""
  };

  $scope.pagingOptions = {
    pageSizes: [25, 50, 100],
    pageSize: 25,
    totalServerItems: 0,
    currentPage: 1
  };

  $scope.setPagingData = function(data, page, pageSize) {
    var pagedData = data.slice((page - 1) * pageSize, page * pageSize);
    $scope.myData = pagedData;
    $scope.pagingOptions.totalServerItems = data.length;
    if (!$scope.$$phase) {
      $scope.$apply();
    }
  };

  $scope.getPagedDataAsync = function(pageSize, page) {
    setTimeout(function() {      
        $http.get('json').success(function(largeLoad) {
          $scope.setPagingData(largeLoad, page, pageSize);
        });
    }, 100);
  };

  $scope.$watch('pagingOptions', function() {
    $scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
  }, true);

  $scope.gridOptions = {
    data: 'myData',
    enablePaging: true,
    pagingOptions: $scope.pagingOptions,
    showFooter: true
  };

  $scope.gridOptions.columnDefs = 'gridColumnDefs';

  // city loc pop state
  $scope.gridColumnDefs = [{
      field: "city"
    },
    {
      field: "state"
    }, {
      field: "pop"
    }, {
      field: "loc"
    }
  ];

});

The HTML code-sample

   <div ng-app="myApp" ng-controller="MyCtrl">
        <div class="gridStyle" ng-grid="gridOptions"></div>
    </div> 
Morganne answered 24/1, 2015 at 11:17 Comment(1)
Can you give client side pagination example pleaseCarabineer

© 2022 - 2024 — McMap. All rights reserved.