dongxichan8627 2019-06-08 03:17
浏览 76

php和angularjs限制偏移的分页

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();

In PHP, the total of records in the database is 100. I did a query to limit 50 records for the first page then 50 records for seconds.

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();
            });
        };

My expectation is the page will loading 50 records first then second 50 records will loading from the server when a user clicked on the second page. This is to avoid large records render at the same time lead to the page is lagging. Therefore.

I using I-lin angularjs datatable server-side processing to achieve my expectation. So far the datatable only displays 50 records not the total of 100 records.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持