【发布时间】:2018-07-20 11:09:20
【问题描述】:
我正在尝试从数据库中获取数据并显示在 jquery DataTable 中,但数据未显示在 DataTable 中。表是
ordered_books with attributes 'BookID', 'BilledNum','BilledDate', 'Qunatity', 'Price', 'Remarks'
查看页面代码
<table id="showBooksIn" class="table table-bordered">
<thead>
<tr>
<th>BOOK ID</th>
<th>BILLED DATE</th>
<th>BILLED NUMBER</th>
<th>QUANTITY</th>
<th>PRICE</th>
<th>REMARKS</th>
</tr>
</thead>
</table>
<script type="text/javascript">
$(document).ready(function(){
$('#showBooksIn').DataTable({
"processing":true,
"serverside":true,
"ajax":{{route('data')}}
"columns":[
{"data": "BookID"},
{"data": "BilledNum"},
{"data": "BilledDate"},
{"data": "Qunatity"},
{"data": "Price"},
{"data": "Remarks"},
]
});
});
</script>
控制器代码
public function index()
{
return view('pages.booksin', $this->fetchData());
}
function fetchData()
{
$ordered_books = OrderedBook::select('BookID', 'BilledNum','BilledDate', 'Qunatity', 'Price', 'Remarks');
return Datatables::of($ordered_books)->make(true); //return an instance of the class or interface you request
}
型号代码
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class OrderedBook extends Model
{
//
}
路线代码
Route::resource('/order','OrderedBookController');
Route::get('/order/data','OrderedBookController@fetchData')->name('data');
我认为问题出在 DataTable javascript 代码上。但我不确定。请帮忙!!!
【问题讨论】:
标签: php jquery laravel laravel-5 datatables