【发布时间】:2016-03-26 14:48:07
【问题描述】:
我已经安装了 yajra/laravel-datatables-oracle "~6.0" 包,用于在 laravel 5.2 中以 MySql 作为数据库来支持服务器端数据表。 我正在尝试显示用户的数据表:
//routes.php
Route::group(['middleware' => ['web'], 'prefix' => 'user'], function () {
Route::get('/index', 'UserController@index')->name('user.index');
});
这是我的控制器:
//UserController.php
public function index()
{
return view('user.index');
}
public function indexData()
{
$users = User::select(['id', 'name', 'email', 'created_at', 'updated_at'])->get();
return Datatables::of($users)->make();
}
观点:
// user\index.blade.php
@extends('layouts.base')
@section('additional_styles')
<link rel="stylesheet" href="//cdn.datatables.net/1.10.7/css/jquery.dataTables.min.css">
@endsection
@section('additional_scripts')
<!-- DataTables -->
<script src="//cdn.datatables.net/1.10.7/js/jquery.dataTables.min.js"></script>
<script>
$('#users-table').DataTable({
"processing": true,
"serverSide": true,
"ajax": '{!! route('user.index') !!}',
"columns": [
{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'email', name: 'email'},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'}
]
});
</script>
@endsection
@section('main-content')
<div class="container">
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-bordered" id="users-table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Created At</th>
<th>Updated At</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
@endsection
但数据表无法正常工作。在处理呈现 tha 数据后,它向我显示响应具有无效 JSON 格式的警报,并说要查看 datatables.net/tn/1。我试图查看 chrome 的开发人员工具以查看响应,但我不能!
对这个问题有任何想法吗?
【问题讨论】:
-
我也遇到过这个问题
标签: datatable laravel-5.2 datatables-1.10