Introduction
This post provides an example about how to create a table via sorting, filter and paging. Following directives and services in AngularJS will be used.
- orderby
- filter
- ng-click
- ng-model
- ng-repeat
I have declared AngularJS Reference.
- <title>Anular Js Filter Example </title>
- <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
- <script src="http://code.angularjs.org/1.4.8/angular.js"></script>
- <script src="http://code.angularjs.org/1.4.8/angular-resource.js"></script>
- <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script>
Now, I created Angular Model, controller, filter, as shown below.
- <script>
- var app = angular.module('MyForm', ['ui.bootstrap', 'ngResource']);
- app.controller('myCtrl', function ($scope) {
- $scope.predicate = 'name';
- $scope.reverse = true;
- $scope.currentPage = 1;
- $scope.order = function (predicate) {
- $scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
- $scope.predicate = predicate;
- };
- $scope.students = [
- { name: 'Thennarasu', age: 24, gender: 'boy',city:'Madurai',Designation:'MCA' },
- { name: 'Karthik', age: 25, gender: 'boy',city:'Theni',Designation:'BE' },
- { name: 'Tony', age: 25, gender: 'boy',city:'Erode',Designation:'MCA' },
- { name: 'Jose', age: 27, gender: 'boy',city:'Kanyakumari',Designation:'MBA' },
- { name: 'Viji', age: 26, gender: 'Girl',city:'TenKasi',Designation:'BSC' },
- { name: 'Prem', age: 25, gender: 'boy',city:'Chennai',Designation:'MBA' },
- { name: 'Senni', age: 30, gender: 'boy',city:'Madurai',Designation:'MCA' },
- { name: 'Mano', age: 27, gender: 'boy',city:'Madurai',Designation:'MCA'},
- { name: 'KarthuPandi', age: 25, gender: 'boy',city:'Theni',Designation:'BE' },
- ];
- $scope.totalItems = $scope.students.length;
- $scope.numPerPage = 5;
- $scope.paginate = function (value) {
- var begin, end, index;
- begin = ($scope.currentPage - 1) * $scope.numPerPage;
- end = begin + $scope.numPerPage;
- index = $scope.students.indexOf(value);
- return (begin <= index && index < end);
- };
- });
- </script>
Style of Grid View Data is shown below.



Summary
Anu VPosted Nov 2, 2016, 8:12 AM
Nice..
Bikesh SrivastavaPosted Nov 2, 2016, 6:32 AM
Good .