Laravel中的数据表分页

Pet*_*ter 2 laravel laravel-5

我正在使用laravel 5.0,我也在使用datatable jquery插件来显示网格。

控制器方法

 public function index() {

    $jobs = \App\Job::orderBy('created_at', 'DESC')->limit(1000)->get();

    return View::make('jobs.index', ['jobs' => $jobs]);
}
Run Code Online (Sandbox Code Playgroud)

问题:现在,我在数据表网格中将-> limit(1000)硬编码为1000个作业以显示它,但是我要显示的记录超过了1000条。

我想要的是?我想用网格显示500条记录,然后显示500条记录。我不确定是否有可用的回调数据表插件功能?我需要一种动态方式来加载下500个

注意:我不愿意使用这种滚动https://datatables.net/extensions/scroller/examples/initialisation/server-side_processing.html的解决方案

Has*_*que 6

您可以使用ajax数据源:

请访问:https : //datatables.net/examples/ajax/objects.html

PHP脚本示例:

// function will process the ajax request
public function getMembers(Request $request) {

        $draw = $request->get('draw');
        $start = $request->get('start');
        $length = $request->get('length');


        $search = (isset($filter['value']))? $filter['value'] : false;

        $total_members = 1000; // get your total no of data;
        $members = $this->methodToGetMembers($start, $length); //supply start and length of the table data

        $data = array(
            'draw' => $draw,
            'recordsTotal' => $total_members,
            'recordsFiltered' => $total_members,
            'data' => $members,
        );

        echo json_encode($data);
    }
Run Code Online (Sandbox Code Playgroud)

JavaScript示例:

$('#all-member-table').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": {
            url: base_url+"ajax/members"
            },
            "columns": [
            { data: '1' },
            { data: '2' },
            { data: '3' },
            { data: '4' },
            { data: '5' },
        ]
    } );
Run Code Online (Sandbox Code Playgroud)

HTML示例:

<table id="all-member-table">
            <thead>
                <tr>
                    <th>Column1</th>
                    <th>Column2</th>
                    <th>Column3</th>
                    <th>Column4</th>
                    <th>Column5</th>
                </tr>
            </thead>
  </table> 
Run Code Online (Sandbox Code Playgroud)