Hello Stackoverflow我正在做一个基于网络的项目现在显示我办公室的所有产品现在我遇到问题现在我有这个页面,我使用数据表服务器端处理
这里的观点:
<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
答案 0 :(得分:0)
您需要两条路线才能工作。第一条路线是用来显示 表视图和第二个路由用于处理dataTables json 响应。在您的示例中,
getAdvanceFilterData
仅适用于 处理json响应。您需要添加其他路线getIndex
class FilesController extends Controller { /** * Displays datatables front end view */ public function getIndex() { return view('files.index'); } /** * Process datatables ajax request. */ public function getAdvanceFilterData() { $files = DB::table('files')->select(array('files.id','files.file_name','files.file_type','files.date','files.username')); return Datatables::of($files)->make(true); } }
执行此操作并加载相应的视图。
控制器类的一个示例
Route::controller('files', 'FilesController', [
'anyData' => 'files.data',
'getIndex' => 'files',
]);
路由
$(function() {
$('#users-table').DataTable({
processing: true,
serverSide: true,
ajax: '{!! route('files.data') !!}',
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}]
});
});
的Javascript
var redis = new Redis({
port: 5008,
host: 'mysite.com',
protocol: "https",
password: "mypasswordencryptedhere"
})