【发布时间】:2019-08-05 14:49:15
【问题描述】:
我必须以数据表的形式显示数据,我使用 YajraBox Laravel 数据表来执行此操作,但它以 JSON 格式显示
/*Route code*/
Route::get('/editing','TlController@modif')->name('modif');
/*the Controller code*/
public function modif(){
return DataTables::of(Weekends::query())->make(true);
}
/*View code*/
@extends('layouts.master')
@section('containers')
<table class="table table-bordered" id="weekends-table">
<thead>
<tr>
<th>idm</th>
<th>fday</th>
<th>sday</th>
<th>id</th>
<th>updated_at</th>
<th>created_at</th>
</tr>
</thead>
<script>
$( document ).ready(function() {
$('#weekends-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('modif') !!}',
columns: [
{ data: 'idm', name: 'id' },
{ data: 'fday', name: 'first day of weekend' },
{ data: 'sday', name: 'second day of weekend' },
{ data: 'created_at', name: 'created_at' },
{ data: 'updated_at', name: 'updated_at' }
]
});
});
</script>
@endsection
这是它表示数据的方式: https://i.imgur.com/ACjPm5a.png
【问题讨论】:
-
您缺少
<tbody>标记,这是 DataTables 所必需的。 -
怎么样?因为我在文档中做了,但我没有得到结果
-
它应该返回 JSON,因为这是插件所期望的。我不使用来自
ajax属性的默认获取请求,但我认为您可能需要仔细检查该路由是否与其兼容。 -
你安装了 snappy pdf 吗?因为本教程中的信息itsolutionstuff.com/post/… 我们应该安装 snappy
标签: php laravel mv yajra-datatable