【发布时间】:2016-08-02 17:48:54
【问题描述】:
我有一个现有的 Laravel 项目,最近才被介绍给 DataTables,并且喜欢它的功能,所以我想在我的项目中实现它。我已按照指南进行操作,但由于某种原因,搜索、分页和过滤器未显示在我的表格中,但实际表格确实显示。
我认为我在主视图中错误地安装了资产,这是我能想到的唯一原因,任何帮助都会很棒。
资源控制器
public function resource()
{
$resources = Resource::with('locations')->get();
return view('pages.resource', compact('resources'));
}
路线
Route::get('resource', array('as'=>'viewResource', 'uses' => 'ResourceController@resource'));
主视图 (app.blade.php)
<!doctype html>
<html lang="en">
......
@yield('scripts')
<!-- Bootstrap Based Data Table Plugin Script-->
<script src="code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css"></script>
<script src="cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
</body>
</html>
resource.blade.php
div class="wrapper">
<section class="panel-primary">
<div class="panel-heading">
<b> Resource Info</b>
</div>
<div class="panel-body">
<table class="table table-hover table-bordered">
<thead>
<th>Name</th>
<th>Description</th>
<th>Address</th>
<th>City</th>
<th>Zip Code</th>
<th>County</th>
</thead>
<tbody>
@foreach($resources as $resource)
@foreach ($resource->locations as $location)
<tr>
<td> {{ $resource->Name }}</td>
<td> {{ $resource->Description }}</td>
<td> {{ $location->Address }}</td>
<td> {{ $location->City }}</td>
<td> {{ $location->Zip_Code }}</td>
<td> {{ $location->County }}</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
</div>
</section>
</div>
@section('scripts')
<script>
$('.resource').DataTable({
select:true,
"order": [[0, "desc"]],
"scrollY" :"380px",
"scrollCollapse": true,
"paging" :true,
"bProcessing" :true
});
</script>
@stop
【问题讨论】:
-
作为不相关的说明,您应该将
bProcessing替换为processing;前者是 v1.10 之前的符号。它会起作用,但与您的其他符号不一致。
标签: php laravel datatables