如何根据第二个数据排序?排序仅适用于 ID。但在我的表格中,我添加了徽章计数,这就是我想要排序的依据。
这是我的控制器
return DataTables::of($users)
->addIndexColumn()
->addColumn('Inventories', function ($row) {
if($row->status != 'Dumped2') {
return '<a href="'.route('admin.clients.show-client-inventories2', $row->id).'" class="btn btn-info btn-sm">'.__("Inventories").' <span class="right badge badge-success" title="Total Lost">'.(abs($row->inv_total_lost_qty) ?? 'N/A').'</span> </a>';
}
})
->addColumn('Returns', function ($row) {
if($row->status != 'Dumped2') {
return ' <a href="'.route('admin.clients.show-client-returns', $row->id) .'" class="btn btn-info btn-sm">'.__('Returns').' <span class="right badge badge-warning" title="Total Returns">'.(abs($row->overall_returns_count) ?? 'N/A').'</span> </a>';
}
$row->status->orderBy(abs($row->overall_returns_count));
})
->addColumn('inbound_shipments', function ($row) {
if($row->status != 'Dumped2') {
return '<a href="'. route('admin.clients.show-client-inbound-shipments', $row->id).'" class="btn btn-info btn-sm">'. __('Inbound Shipments').'<span class="right …Run Code Online (Sandbox Code Playgroud) 在我的 Laravel 5.6 应用程序中,我尝试将一个$id变量从我的路由传递到我的数据表的每一列。
我的代码:
public function getVendorslistChange($id){
try {
return Datatables::of($this->purchaseRepository->getVendorListData(),$id)
->addColumn('action', function ($vendor,$id) {
return \Form::open(['method' => 'POST', 'action' => ['PurchaseController@postChangeVendor',$id], 'class' => 'form']) . '
<input type="hidden" name="id" value="' . $vendor->id . '" />
<input type="submit" name="submit" value="Choose" class="btn center-block" />
' . \Form::close();
})
->make(true);
} catch (\Exception $e) {
return $this->redirectWithErrors($e);
}
}
Run Code Online (Sandbox Code Playgroud)
这部分$this->purchaseRepository->getVendorListData()将返回以下内容:
public function getVendorListData(){
$this->vendors = Vendor::Select(
array(
'vendors.id',
'vendors.company_name'
))
->where('vendors.company_id',return_company_id())
->where('status','Active')->get()
;
return $this->vendors;
}
Run Code Online (Sandbox Code Playgroud)
但是有错误说, …
我有两个模型,User并且它们之间Training有Many to many关系.我正在使用Laravel Datatables包显示所有用户的表.这是数据控制器方法(检索查询结果并创建Datatables表)的方式如下所示:
public function getData()
{
$users = User::select(array('users.id', 'users.full_name', 'users.email', 'users.business_unit', 'users.position_id'))
->where('users.is_active', '=', 1);
return \Datatables::of($users)
->remove_column('id')
->make();
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能添加一列到创建的表,该表显示关系的总数为每个用户(也就是,有多少Training小号是否每个User都有)?