PHP (Laravel 4.2)
//PHP function
$rowsPerPage = 50;
$num = 1;
$offsets = ($num - 1) * $rowsPerPage;
$data['trans'] = Transaction::withoutBranch()
->select('id', 'amount')
->where('payment_date', '>=', '2019-05-06')
->limit($rowsPerPage)
->offset($offsets)
->get();
В PHP общее количество записей в базе данных составляет 100. Я сделал запрос, чтобы ограничить 50 записей для первой страницы, а затем 50 записей для секунд.
AngularJS
//api call from PHP funtion
fetchTrx: function (data) {
return api.call('api/bank_recon/fetch_trx', data);
},
//controller
.controller('bankReconCtrl', function ($scope, $state, Module,
CSRF_TOKEN, toastr, $controller, actionBar, $compile,DTOptionsBuilder) {
var vm = this;
vm.dtOptions = DTOptionsBuilder.newOptions()
.withOption('ajax', {
// Either you specify the AjaxDataProp here
url: 'api/bank_recon/fetch_trx',
type: 'POST',
})
.withDataProp('data')
.withOption('processing', true)
.withOption('serverSide', true)
.withPaginationType('full_numbers');
////api call from PHP funtion
$scope.fetchTrx = function () {
Module.fetchTrx({
month: $scope.item.month,
year: $scope.item.year,
account_id: $scope.item.account_id,
page_number: $scope.item.page_number
}).then(function(res) {
angular.forEach(res.trans, function (trx) {
});
$scope.trans = res;
console.log($scope.trans);
$scope.item.reconcile_date = res.reconcile_date;
// console.log($scope.trans.photos);
$scope.item.actual_balance =
Math.roundCurrency(res.actual_balance);
$scope.item.end_balance =
Math.roundCurrency(res.end_balance);
$scope.form.$setPristine();
}).finally(function () {
// calculate
$scope.calBalance();
});
};
Я ожидаю, что страница будет загружать сначала 50 записей, затем вторые 50 записей будут загружаться с сервера, когда пользователь нажимает на вторую страницу. Это сделано для того, чтобы избежать больших записей при одновременном задержке страницы. Поэтому.
Я использовал обработку данных на сервере I-lin angularjs для достижения моих ожиданий. До сих пор в базе данных отображаются только 50 записей, а не 100 записей.