如何在阵列上使用Laravel Pagination滑块

时间:2016-04-28 03:10:53

标签: laravel pagination

我的视图调用JavaScript函数向控制器提交帖子,控制器又生成一个数组并根据数组返回一个分页对象。我使用了Paginator :: make,它正在运行。但我想在返回的对象上有一个“智能”的页面范围。

我的JavaScript代码如下:

$('form#form-retrieve-data').submit(function(){
    $.post(
        'mysite.com/retrieve', //route for the action page
        {
            "_token": $( this ).find( 'input[name=_token]' ).val(),
            'from-date': '2016-04-01',
            'to-date': '2016-04-15',
            'per-page': 20,
            'page-number': 1
        },
        function(data){
            var current_page = data.current_page;
            var retrieve_data = data.data;
            var start_page = data.from; //first page of the page range
            var last_page = data.last_page; //last page of the page range
            var per_page = data.per_page;

            $.each(retrieve_data, function(i, val){
                //handle each retrive data hare
            }

            for(var i = start_page; i <= last_page; i++){
                //create the page links here
            }
        },
        'json'
    );

    return false;
});

操作页面的控制器返回分页对象:

$from_date = Input::get('from-date');
$to_date = Input::get('to-date');
$currentPage = Input::get('page-number', 1) - 1;
$perPage = Input::get('per-page');

$retrieved_data = array(); //array that will hold elements to be returned back

//code to get retrieved data and push to array $retrieved_data

$pagedData = array_slice($retrieved_data, $currentPage * $perPage, $perPage); 
//$response = Paginator::make($pagedData, count($retrieved_data), $perPage); //this was ok but I want an "intelligent range of pages
$response = Paginator::slider($pagedData, count($retrieved_data), $perPage); //I was hoping that the returned first and last pages would be the "intelligent" range

return Response::json($response);

是否可以在数组上使用Paginator :: slider与Paginator :: make相同?

由于

0 个答案:

没有答案