【发布时间】:2017-01-26 08:53:26
【问题描述】:
你好 Stackoverflow 我现在正在做一个基于 Web 的项目,显示我办公室的所有产品现在我遇到了问题现在我有这个页面并且我使用了数据表服务器端处理
这里是视图:
<table id="dloadTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>File ID Number</th>
<th>File Name</th>
<th>File Type</th>
<th>Date Issued</th>
<th>Uploader</th>
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>File ID Number</th>
<th>File Name</th>
<th>File Type</th>
<th>Date Issued</th>
<th>Uploader</th>
<th>Action</th>
</tr>
</tfoot>
</table>
控制器:
public function getAdvanceFilterData()
{
$files = Files::select(array('files.id','files.file_name','files.file_type','files.date','files.username'));
return Datatables::of($files)->make(true);
路线:
Route::get('/getfilesdata', 'FileController@dloadFile');
还有js:
$(document).ready(function() {
var oTable = $('#dloadTable').DataTable({
processing: true,
serverSide: true,
ajax: {
url: '/getfilesdata',
dataSrc:""
},
order: [[1,'desc']],
columnDefs: [ { //this prevents errors if the data is null
targets: "_all",
defaultContent: ""
} ],
columns: [
{data: 'id', name: 'files.id'},
{data: 'file_name', name: 'files.file_name'},
{data: 'file_type', name: 'files.file_type'},
{data: 'date', name: 'files.date'},
{data: 'username', name: 'files.username'},
{data: 'action', name: 'action', orderable: false, searchable: false}
]
});
} );
当我尝试检查我在控制器中得到的不是我期望它不返回 JSON 数据的数据时,我应该怎么做? TIA
【问题讨论】:
-
files是您数据库中的表吗? -
是的,彼得是我数据库中表的名称之一
-
您是否检查过
$files中的数据是否正确? -
@PeterDarmis 是的,我已经检查过了,但不幸的是它不是 JSON 格式,你可以在这里检查drive.google.com/file/d/0BwwBLqPiSk-9OXZEazU2Y09ieHM/…
-
这是
$files中服务器端返回的内容吗?没关系。你能检查var_dump(Datatables::of($files)->make(true));的输出吗?
标签: php laravel server-side datatables-1.10 laravel-4.2