分页上的Laravel Yajra分页不起作用

时间:2019-12-06 04:37:34

标签: php laravel datatable

我正在一个使用API​​的项目中,它包含很多数据,因此我需要一个数据表来管理所有数据。不幸的是,当我应用数据表时,分页不起作用,当我单击该分页时,页面已加载,并且显示了第一页的内容。有什么解决办法吗?

这是我的控制器代码

public function json()
{
    $token = session()->get('accessToken');
    $ch = curl_init('http://api-link');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-access-token:' . $token . ''));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $response = curl_exec($ch);
    curl_close($ch);
    $data_response = json_decode($response)->data;
    return Datatables::of($data_response)->make(true);
}

这是我的刀片服务器代码

@section('content')
<div id="page-content" class="page-content">    
    <div id="page-content-scroll"><!--Enables this element to be scrolled -->   
        <div class="content">
            @component('layouts.topnav-admin')@endcomponent
            <a href="/tag/create" class="button button-red button-full button-rounded button-s uppercase ultrabold button-add">Tambah</a>
            <table class="table-borders-dark table-list" id="table_tag">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                    </tr>
                </thead>
            </table>

        </div>
    </div>
</div>
@endsection

@section('script')
<script>

    $(document).ready(function () {
        $('#table_tag').DataTable({
            processing: true,
            serverSide: true,
            order: [[ 0, "desc" ]],
            ajax: {
                url: "tag/json",
                type: "GET",
            },
            columns: [
                {data: 'id', name: 'id', render:function(data, type, row){
                        return "<a href='/tag/edit/"+ row.id +"'>" + row.id + "</a>"},
                },
                {data: 'name', name: 'name', render:function(data, type, row){
                        return "<a href='/tag/edit/"+ row.id +"'>" + row.name + "</a>"},
                },
            ]
        });
    });

</script>
@endsection

这是用于响应数据

// 20191206112726
// http://localhost:8000/tag/json

{
    "draw": 0,
    "recordsTotal": 40,
    "recordsFiltered": 40,
    "data": [
        {
            "id": "16",
            "name": "abc"
        },
        {
            "id": "19",
            "name": "xyz"
        },
        {
            "id": "30",
            "name": "athletic"
        }
    ],
    "input": [

    ]
}

谢谢

0 个答案:

没有答案