Laravel 排序和提取大数据时出现问题(yajra datatables)
在应用列排序时,从Laravel 排序和提取大数据时出现问题(yajra datatables),laravel,laravel-5,large-data,yajra-datatable,Laravel,Laravel 5,Large Data,Yajra Datatable,在应用列排序时,从yajra datatable服务器端提取大数据时出现问题 对于列排序,我在查询生成器中使用了get()。如果我避免使用它并使用orderBy,它可以很好地工作并更快地获取记录,但问题是列排序不起作用 $query = DB::table('clients'); if(Auth::user()->role_id==2) { $clients= $query->whereRaw('user_id',Auth::
yajra datatable
服务器端提取大数据时出现问题
对于列排序,我在查询生成器中使用了get()
。如果我避免使用它并使用orderBy,它可以很好地工作并更快地获取记录,但问题是列排序不起作用
$query = DB::table('clients');
if(Auth::user()->role_id==2)
{
$clients= $query->whereRaw('user_id',Auth::id());
}
else if(Auth::user()->role_id==3)
{
$getCompanyId = User::where('id',Auth::id())
->first();
$clients= $query->whereRaw('user_id',$getCompanyId['added_by']);
}
$clients= $query->orderBy('id');
$clients = $query->select();
$clients = $query->get();
$datatables = datatables()->of($clients)
->addColumn('action', function ($clients) {
return '<button class="btn btn-xs buttonhover" data-id='.$clients->id.' data-backdrop="static" onclick="editClient(this);"><i class="fa fa-edit" aria-hidden="true"></i> Edit</button>
<button class="btn btn-xs buttonhover2" data-id='.$clients->id.' onclick="viewDetails(this);"><i class="fa fa-eye" aria-hidden="true"></i> View</button>
<button class="btn btn-xs buttondeletehover"data-id='.$clients->id.' onclick="confirmAlertBox(this)"><i class="fa fa-trash" aria-hidden="true"></i> Delete</button>';
})
->make(true);
return $datatables;
$query=DB::table('clients');
if(Auth::user()->role_id==2)
{
$clients=$query->whereRaw('user_id',Auth::id());
}
else if(Auth::user()->role_id==3)
{
$getCompanyId=User::where('id',Auth::id())
->第一个();
$clients=$query->whereRaw('user_id',$getCompanyId['added_by']);
}
$clients=$query->orderBy('id');
$clients=$query->select();
$clients=$query->get();
$datatables=datatables()->of($clients)
->addColumn('action',函数($clients){
返回“编辑”
看法
删除';
})
->使(真实);
返回$datatables;
不要在数据表中使用,也不要获取()数据。而是使用eloquent生成datatables对象并查询sellect:
$users = User::query();
return DataTables::eloquent($users)
->toJson();
或者使用order by生成有说服力的对象:
$users = User::orderBy('id');
select()有什么问题