Skip to content

Instantly share code, notes, and snippets.

@telagraphic
Last active December 18, 2015 19:28
Show Gist options
  • Save telagraphic/5832706 to your computer and use it in GitHub Desktop.
Save telagraphic/5832706 to your computer and use it in GitHub Desktop.
// data to paginate
$scope.getBrokerSales = function () {
$scope.resultMessage = 'Searching...';
var searchCriteria = {
fromDate: $scope.fromDate,
toDate: $scope.toDate,
};
BrokerSalesService.executeBrokerSalesSearch(searchCriteria).then(function (data) {
$scope.brokerSaleResults = data;
if (!$scope.brokerSaleResults || $scope.brokerSaleResults.length <= 0) {
$scope.resultMessage = 'No results were found';
} else {
$scope.resultMessage = 'Please enter your search criteria';
}
});
};
// pagination code
$scope.filterOptions = {
filterText: "",
useExternalFilter: true
};
$scope.pagingOptions = {
pageSizes: [5, 10, 20],
pageSize: 5,
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, searchText) {
var data = $scope.getBrokerSales;
$scope.setPagingData(data, page, pageSize);
};
$scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage);
$scope.$watch('pagingOptions', function (newVal, oldVal) {
if (newVal !== oldVal && newVal.currentPage !== oldVal.currentPage) {
$scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
}
}, true);
$scope.$watch('filterOptions', function (newVal, oldVal) {
if (newVal !== oldVal) {
$scope.getPagedDataAsync($scope.pagingOptions.pageSize, $scope.pagingOptions.currentPage, $scope.filterOptions.filterText);
}
}, true);
$scope.gridOptions = {
data: 'brokerSaleResults',
enablePaging: true,
showFooter: true,
pagingOptions: $scope.pagingOptions,
filterOptions: $scope.filterOptions,
canSelectRows: false,
displaySelectionCheckbox: false,
footerRowHeight: 35,
showGroupPanel: true,
showColumnMenu: true,
showFilter: true,
enableColumnResize: true,
sortInfo: { fields: ['SignupDate'], directions: ['asc'] },
columnDefs: [...]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment