我试图使链接到另一个视图的 ID 的行值可点击。这可以在前端使用来自 jQuery 的常规数据表来实现,例如:<td><h6><a href="/users/{{ $user->id }}">{{ $user->id }}</a></h6></td>
. 但是我该如何使用 yajra 呢?出于某种原因,yajrabox.com 最终无法加载,因此我无法阅读他们的文档。我也找不到相关的教程。这是我到目前为止所拥有的。
用户控制器:
public function index()
{
return view('users.index');
}
public function yajraDT()
{
return Datatables::of(User::query())->make(true);
}
index.blade.php:
<div class="container">
<h2>Laravel DataTables Tutorial Example</h2>
<table class="table table-bordered" id="tableDT">
<thead>
<tr>
<th class="text-left">Id</th>
<th class="text-left">First Name</th>
<th class="text-left">Last Name</th>
<th class="text-left">Email</th>
<th class="text-left">Gender</th>
@if(Auth::check() && Auth::user()->type == "Admin")
<th class="text-left">Actions</th>
@endif
</tr>
</thead>
</table>
<script>
$(function() {
$('#tableDT').DataTable({
processing: true,
serverSide: true,
ajax: '{{ url('users/yajraDT') }}',
columns: [
{ data: 'id', name: 'id' },
{ data: 'first_name', name: 'first_name' },
{ data: 'last_name', name: 'last_name' },
{ data: 'email', name: 'email' },
{ data: 'gender', name: 'gender' }
]
});
});
</script>
路线网:
Route::get('users/yajraDT', 'UsersController@yajraDT');
Route::resource('users', 'UsersController');