从ajax调用加载数据时,引导数据表搜索和分页不起作用

时间:2017-11-13 05:49:40

标签: laravel laravel-5 datatables laravel-5.2 laravel-5.3

我正在尝试使用Laravel中的bootstrap数据表。我的数据加载成功,但数据表搜索和分页不起作用。请帮助我。

我页面上的Html代码就是那样

<table id="example111" class="table table-striped nowrap www" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th class="col-sm-2 col-lg-1">Sr.No.</th>
            <th>Department Name</th>
            <th class="col-sm-3 col-lg-2">Edit/Delete</th>
        </tr>
    </thead>
    <tbody class="departmentlist" id="departmentlist111"></tbody>
</table>

我在这个页面上的ajax调用

<script type="text/javascript" language="javascript" class="init">
$(document).ready(function() {
    table = $('#example111').DataTable({
        paging: false,
    });

    table.destroy();

    $('#example111').DataTable({
        "serverSide": true,
        "ajax": {
            "url": "<?= URL::to('show_department')?>",
            "dataType": "json",
            "type": "post",
            "data":{ _token: "{{csrf_token()}}"},
            "dataSrc": function (e) {
                $("#departmentlist111").html(e);
            }
        }
    });
});
</script>

我在页面上的路线呼叫就像

Route::post('show_department','admin\DepartmentController@show_department');

我的控制器电话

public function show_department()
{
    $cartdata = '<tr>
                 <td class="col-sm-2 col-lg-1"> 1</td>
                 <td >South Indian</td>
                 <td class="col-sm-3 col-lg-2">
                 <button type="button" class="btn btn-info btn-sm"><i class="glyphicon glyphicon-edit"></i></button>
                 <button type="button" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-remove"></i></button>
                 </td>
                 </tr>
                 <tr>
                 <td class="col-sm-2 col-lg-1"> 1</td>
                 <td >South </td>
                 <td class="col-sm-3 col-lg-2">
                 <button type="button" class="btn btn-info btn-sm"><i class="glyphicon glyphicon-edit"></i></button>
                 <button type="button" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-remove"></i></button>
                 </td>
                 </tr>
                 <tr>
                 <td class="col-sm-2 col-lg-1"> 1</td>
                 <td> Indian</td>
                 <td class="col-sm-3 col-lg-2">
                 <button type="button" class="btn btn-info btn-sm"><i class="glyphicon glyphicon-edit"></i></button>
                 <button type="button" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-remove"></i></button>
                 </td>
                 </tr>
                 <tr>
                 <td class="col-sm-2 col-lg-1"> 1</td>
                 <td >South Indian</td>
                 <td class="col-sm-3 col-lg-2">
                 <button type="button" class="btn btn-info btn-sm"><i class="glyphicon glyphicon-edit"></i></button>
                 <button type="button" class="btn btn-danger btn-sm"><i class="glyphicon glyphicon-remove"></i></button>
                 </td>
                 </tr>';

    echo json_encode($cartdata);        
}

所以请解决我的错误。

0 个答案:

没有答案