Laravel Yajra Datatable 问题与分页和 recordsFiltered
Posted
技术标签:
【中文标题】Laravel Yajra Datatable 问题与分页和 recordsFiltered【英文标题】:Laravel Yajra Datatable issue with pagination and recordsFiltered 【发布时间】:2018-12-07 08:03:47 【问题描述】:控制器:
use Datatables;
public function index(Request $request)
$services = Service::select(['id', 'name_en', 'name_ar', 'color', 'duration', 'friday', 'saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'created_at']);
return Datatables::eloquent($services)->addColumn('action','
<div class="card-action">
<button type="button" class="background-green edit-service" data-toggle="tooltip" data-placement="top" data-original-title="Edit">
<i class="fa fa-edit" data-toggle="modal" data-target="#edit-service"></i>
</button>
<button type="button" class="sweet-5 background-red remove-service" data-toggle="tooltip" data-placement="top" data-original-title="Delete">
<i class="fa fa-trash"></i>
</button>
</div>
')->make(true);
路线:
Route::get('servicesAPI' , [
'uses' => 'ServiceController@index',
'as' => 'servicesAPI.index',
'middleware' => 'roles',
'roles' => ['Admin', 'View Services'],
]);
AJAX:
$(function()
$('#services_table').DataTable(
processing : true,
serverSide : true,
responsive : true,
stateSave : true,
autoWidth : true,
lengthMenu : [[5, 10, 15, 25, 50, 100], [5, 10, 15, 25, 50, 100]],
paging : true,
pagingTypeSince : 'numbers',
pagingType : 'full_numbers',
ajax : 'servicesAPI',
deferRender: true,
order: [[ 10, "asc" ]],
columns : [
data: 'name_en', name: 'name_en',
"render": function ( data, type, row )
return '<b style="color:'+row['color']+'">' + data + '</b>';
,
data: 'color', name: 'color' , visible: false,
data: 'duration', name: 'duration' ,
"render": function ( data, type, row )
return data + ' Min';
,
data: 'saturday', name: 'saturday',
"render": function ( data, type, row )
switch (data)
case '0':
return '<i class="fa fa-close text-red"></i>';
break;
case '1':
return '<i class="fa fa-check text-blue"></i>';
break;
,
data: 'sunday', name: 'sunday',
"render": function ( data, type, row )
switch (data)
case 0:
return '<i class="fa fa-close text-red"></i>';
break;
case '1':
return '<i class="fa fa-check text-blue"></i>';
break;
,
data: 'monday', name: 'monday',
"render": function ( data, type, row )
switch (data)
case 0:
return '<i class="fa fa-close text-red"></i>';
break;
case '1':
return '<i class="fa fa-check text-blue"></i>';
break;
,
data: 'tuesday', name: 'tuesday',
"render": function ( data, type, row )
switch (data)
case 0:
return '<i class="fa fa-close text-red"></i>';
break;
case '1':
return '<i class="fa fa-check text-blue"></i>';
break;
,
data: 'wednesday', name: 'wednesday',
"render": function ( data, type, row )
switch (data)
case 0:
return '<i class="fa fa-close text-red"></i>';
break;
case '1':
return '<i class="fa fa-check text-blue"></i>';
break;
,
data: 'thursday', name: 'thursday',
"render": function ( data, type, row )
switch (data)
case 0:
return '<i class="fa fa-close text-red"></i>';
break;
case '1':
return '<i class="fa fa-check text-blue"></i>';
break;
,
data: 'friday', name: 'friday',
"render": function ( data, type, row )
switch (data)
case 0:
return '<i class="fa fa-close text-red"></i>';
break;
case '1':
return '<i class="fa fa-check text-blue"></i>';
break;
,
data: 'id', name: 'id' , visible: false,
data: 'action', name: 'action', orderable: false, searchable: false
]
);
);
查看:
<table id="services_table" class="table table-bordered table-center table-striped">
<thead>
<tr>
<th>@lang('services.service_name')</th>
<th>@lang('services.color')</th>
<th>@lang('services.duration')</th>
<th>@lang('services.sat')</th>
<th>@lang('services.sun')</th>
<th>@lang('services.mon')</th>
<th>@lang('services.tue')</th>
<th>@lang('services.wed')</th>
<th>@lang('services.thu')</th>
<th>@lang('services.fri')</th>
<th>@lang('services.service_created')</th>
<th>@lang('clients.action')</th>
</tr>
</thead>
</table>
网络:
draw: 5, recordsTotal: 12, recordsFiltered: 12, data: [,…] draw: "5", columns: [data: "name_en", name: "name_en", searchable: "true" orderable: "true",...,...],... 记录过滤:12 记录总数:12
排序正常,它返回新数据并且正确。 改变长度(每页)正在工作。 但由于分页不起作用 记录过滤:12 记录总数:12 它应该是: 记录过滤:5 或 10(每页) 记录总数:12
什么原因?
更新:终于成功了! ..我更新了 jquery.datatables.min.js 从 v1.10.7 到 v1.10.19,无需降级 Yajra Datatable 或 升级 jquery.datatables.min.css
【问题讨论】:
终于成功了! .. 我将 jquery.datatables.min.js 从 v1.10.7 更新到 v1.10.19 完美它工作正常。 @DanielY.Naguib 发布您所做的更改作为答案并接受它,以便对其他人也有用 @NeelBhanushali 完成了我的朋友 【参考方案1】:终于成功了! .. 我将 jquery.datatables.min.js 从 v1.10.7 更新到 v1.10.19,而没有降级 Yajra Datatable 或升级 jquery.datatables.min.css
【讨论】:
我遇到了类似的问题,如果我点击任何分页链接,它会绘制相同的记录。将 js 文件从 1.10.21 降级到 1.10.20 似乎可以解决我的问题以上是关于Laravel Yajra Datatable 问题与分页和 recordsFiltered的主要内容,如果未能解决你的问题,请参考以下文章
在 Laravel 8 中使用 yajra 数据表加载 DataTable where select
Laravel Yajra Datatable 问题与分页和 recordsFiltered
Laravel,Yajra Datatable,如果 y 那么如何返回 Yes else No
编辑列日期格式后不显示过滤日期 - Laravel Yajra Datatable