[英]Yajra DataTable (search box and loading data) response very slow around 15 sec. and more
I'm using Yajra DataTable with Laravel.我在 Laravel 中使用Yajra DataTable 。 but the table loaded very small and take around 15 seconds and more.
但是加载的表非常小,大约需要 15 秒或更长时间。 The reason is the for loop and if conditions inside
addColumn
, which make it slow.原因是 for 循环和
addColumn
中的 if 条件,这使得它变慢了。
I only know this way (by using addColumn
) to embed html tags in the table.我只知道这种方式(通过使用
addColumn
)在表格中嵌入 html 标签。 While I need to put select tag, buttons, and other links based on some conditions.虽然我需要根据某些条件放置选择标签、按钮和其他链接。 where these tags make loading the table very slow.
这些标签使加载表格的速度非常慢。
This is my Ajax code:这是我的 Ajax 代码:
var allUsersTable = $('.allleads').DataTable({
processing: true,
serverSide: true,
ajax: {
url: "customer/GetAllcusts",
},
columns: [
{"data": "note", "name": "note", orderable: false, searchable: false},
{"data": "sms", "name": "sms"},
{"data": "assign", "name": "assign"},
],
bSort: false,
dom: 'Bfrtip',
buttons: [
'excel', 'pdf', 'print', 'colvis'
]
});
and herein the function in controller to load the data:这里是控制器中加载数据的函数:
return DataTables::of($allClients)
->addColumn('note', function ($allClient) {
return '<a style="cursor: pointer" title="Add Note" onclick="addNotes(' . $allClient->id . ',' . $allClient->quote_id . ',this)"><i class="material-icons">event_note </i></a>';
})
->addColumn('sms', function ($allClient) {
return '<a style="cursor: pointer" title="Send SMS" id="send_smsclick" onclick="send_smsclick(' . $allClient->id . ',' . $allClient->primary_number . ')" ><i class="material-icons notranslate">message</i></a>';
})
->addColumn('assign', function ($allClient) use ($user_status, $all_users) {
if ($user_status == 'Admin') {
$options = '<option hidden="true">Select Stuff...</option>';
foreach ($all_users as $users) {
if ($allClient->user_id == $users->id) {
$options = $options . '<option value = "' . $users->id . '" disabled selected >' . $users->name . '</option >';
} else {
$options = $options . '<option value = "' . $users->id . '" >' . $users->name . '</option>';
}
}
return '<select name="user_id" class="form-control activity_status"
onchange="assign_users(' . $allClient->id . ', this)" >' . $options . ' </select>';
} else {
$query = User::find($allClient->user_id);
return $query->name;
}
})
->rawColumns(['note', 'sms', 'assign'])
->make(true);
I will appreciate any hep to improve the speed to load the table, and lunch the data as well.我将不胜感激任何可以提高加载表速度和午餐数据的帮助。
Thank u感谢你
change:改变:
processing: true,
serverSide: true,
to:到:
processing: false,
serverSide: false,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.