0
我試圖在我的Laravel應用程序中顯示一些數據,但由於某種原因,顯示不正確。我正在使用這個包:https://github.com/yajra/laravel-datatablesLaravel DataTable不顯示數據
<table class="table table-bordered table-striped" id="best-sold-table-sort">
<thead>
<tr>
<th>{{ trans('labels.backend.table.store.best_sold.product') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.revenue') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.sold') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.discount') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.price_excl') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.price_incl') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.margin') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.profit') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.roas') }}</th>
<th>{{ trans('labels.backend.table.store.best_sold.exclude_reason') }}</th>
</tr>
</thead>
<tbody class="show-when-sibling-is-empty">
<tr>
<td colspan="10"><em>{{ trans('strings.backend.stores.tables.no_products') }}</em></td>
</tr>
</tbody>
</table>
這是被填寫的表。
let type = 'salable';
let channel = 'general';
date = '1 January 2017 - 31 December 2017';
let table = $('#best-sold-table-sort').DataTable({
'processing': true,
'serverSide': true,
'ajax': '{!! route('admin.ajax.dashboard.best_sold.get') !!}/' + type + '/' + channel + '/' + date,
'responsive': true,
'paging': false,
'lengthChange': false,
'searching': false,
'ordering': true,
'info': false,
'autoWidth': false,
'columns': [
{data: 'title', name: 'title'},
{data: 'revenue', name: 'revenue'},
{data: 'stock_sold', name: 'stock_sold'},
{data: 'discount', name: 'discount'},
{data: 'price_excl', name: 'price_excl'},
{data: 'price_incl', name: 'price_incl'},
{data: 'margin', name: 'margin'},
{data: 'profit', name: 'profit'},
{data: 'roas_target', name: 'roas_target'},
{data: 'exclude_reason', name: 'exclude_reason'},
],
});
這是我的腳本。
public function getBestSoldData(Request $request) {
return Datatables::of(\DB::table('aggregated_to_best_sold'))->make(true);
}
這是被ajax路由調用的函數。
Route::get('dashboard/get/bestSoldTable/{type?}/{channel?}/{date?}', 'Ajax\[email protected]')
->name('dashboard.best_sold.get');
這是我的路由文件。
https://imgur.com/IeoWRjU這是我通過ajax調用返回的響應的一部分。我檢查了JSON是有效的。 我認爲這與DataTables的繪圖功能有關。據我所知,它應該顯示在表中重新繪製的行數量,在我的JSON響應中,它是1或0.
我希望有人能夠幫助到底。
你不應該有'tbody'在HTML,DataTable將自己顯示沒有結果消息。 – TheFallen
啊,似乎已經做了伎倆,謝謝你。 –