JS file:
var adminmodule=angular.module('tasteapp',['ngRoute','ngResource','ui.bootstrap']);
adminmodule.filter('startFrom', function () {
return function(input, start) {
if (!angular.isArray(input)) {
return [];
}
start = +start; //parse to int
return input.slice(start);
};
});
OR
adminmodule.filter('startFrom', function() {
return function(input, start) {
if (!input || !input.length) { return; }
start = +start; //parse to int
return input.slice(start);
}
});
/*Users management*/
adminmodule.controller("userslist", ["$scope", "$http","$filter","$timeout" , function($scope, $http,$filter,$timeout) {
$scope.message="user history";
$http.get(base_ur+"/users/userlistdata").success(function(response) {//$scope.userdata = response;
$scope.users = response;
if($scope.users.length > 0)
{
for(var i=0; i< $scope.users.length;i++)
{
$scope.users[i].sr_no = i+1;
}
}
$scope.currentPage = 1; //current page
$scope.entryLimit = 10; //max no of items to display in a page
$scope.filteredItems = $scope.users.length; //Initially for no filter
console.log($scope.filteredItems);
$scope.totalItems = $scope.users.length;
$scope.itemsPerPage = $scope.entryLimit;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.setItemsPerPage = function(num) {
$scope.itemsPerPage = num;
$scope.currentPage = 1; //reset to first paghe
};
$scope.sort = function(keyname){
$scope.sortKey = keyname; //set the sortKey to the param passed
$scope.reverse = !$scope.reverse; //if true make it false and vice versa
}
}])
Controller file:
public function userlistdata()
{
$usersresult = $this->usermodel->getuserList();
echo json_encode($usersresult);
}
View file:
<tr ng-repeat="user in filtered = (users | filter:search | orderBy : sortKey :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit"></tr>
<div class="col-md-12" style = "margin-left: 10px;" ng-show="filteredItems > 0">
<pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()" class="pagination-sm" items-per-page="itemsPerPage"></pagination>
</div>
var adminmodule=angular.module('tasteapp',['ngRoute','ngResource','ui.bootstrap']);
adminmodule.filter('startFrom', function () {
return function(input, start) {
if (!angular.isArray(input)) {
return [];
}
start = +start; //parse to int
return input.slice(start);
};
});
OR
adminmodule.filter('startFrom', function() {
return function(input, start) {
if (!input || !input.length) { return; }
start = +start; //parse to int
return input.slice(start);
}
});
/*Users management*/
adminmodule.controller("userslist", ["$scope", "$http","$filter","$timeout" , function($scope, $http,$filter,$timeout) {
$scope.message="user history";
$http.get(base_ur+"/users/userlistdata").success(function(response) {//$scope.userdata = response;
$scope.users = response;
if($scope.users.length > 0)
{
for(var i=0; i< $scope.users.length;i++)
{
$scope.users[i].sr_no = i+1;
}
}
$scope.currentPage = 1; //current page
$scope.entryLimit = 10; //max no of items to display in a page
$scope.filteredItems = $scope.users.length; //Initially for no filter
console.log($scope.filteredItems);
$scope.totalItems = $scope.users.length;
$scope.itemsPerPage = $scope.entryLimit;
});
$scope.setPage = function(pageNo) {
$scope.currentPage = pageNo;
};
$scope.filter = function() {
$timeout(function() {
$scope.filteredItems = $scope.filtered.length;
}, 10);
};
$scope.setItemsPerPage = function(num) {
$scope.itemsPerPage = num;
$scope.currentPage = 1; //reset to first paghe
};
$scope.sort = function(keyname){
$scope.sortKey = keyname; //set the sortKey to the param passed
$scope.reverse = !$scope.reverse; //if true make it false and vice versa
}
}])
Controller file:
public function userlistdata()
{
$usersresult = $this->usermodel->getuserList();
echo json_encode($usersresult);
}
View file:
<tr ng-repeat="user in filtered = (users | filter:search | orderBy : sortKey :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit"></tr>
<div class="col-md-12" style = "margin-left: 10px;" ng-show="filteredItems > 0">
<pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()" class="pagination-sm" items-per-page="itemsPerPage"></pagination>
</div>
No comments:
Post a Comment