我正在使用带有 laravel 5.8 的 yajra laravel 数据表包。数据表未显示在我的视图中。我在 jquery 之后添加了数据表。我无法弄清楚问题出在哪里。帮我解决这个问题。谢谢。
数据表脚本:
$(document).ready( function () {
$('#appointment-datatable').DataTable({
processing: true,
serverSide: true,
ajax: '/get_appointment_data',
columns:
[
{
data: 'id',
name: 'id'
},
{
data: 'date',
name: 'date'
},
{
data: 'time',
name: 'time'
},
{
data: 'payment_status',
name: 'payment_status'
}
]
})
} );
控制器代码:
public function getAppointmentData(Request $request)
{
if ($request->ajax())
{
$getData = DB::table('jobs')->select('id', 'date', 'time', 'payment_status', 'amount')->get();
$datatable = DataTables::of($json)->make(true);
return $datatable;
}
}
public function ShowAppointments(Request $request)
{
return view('admin.show_appointments');
}
路线:
Route::get('/show_appointments', 'NavigationController@ShowAppointments')->name('show_appointments');
Route::get('/get_appointment_data', 'NavigationController@getAppointmentData');
我想在 admin.show_appointments 视图中显示数据表返回 ShowAppointments 方法
视图中的 HTML:
<table class="table" id="appointment-datatable">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">date</th>
<th scope="col">time</th>
<th scope="col">payment_status</th>
<th scope="col">amount</th>
</tr>
</thead>
</table>
我以前从未使用过数据表,而且我是 laravel 的新手。感谢你的帮助
一只斗牛犬
拉风的咖菲猫
慕盖茨4494581
随时随地看视频慕课网APP