私はajaxとサーバーサイドスクリプトでyajraデータテーブルを使用しています。 検索は問題なく機能しますが、並べ替えボタンをクリックしても何も起こりません。
私のコントローラー
$suppliers = DB::table("suppliers")
->select(
'suppliers.id',
'suppliers.created_at',
'suppliers.email',
'suppliers.status',
'companies.id as company_id',
'companies.name',
'company_categories.title',
DB::raw('
(select COUNT(promotions.company_id) FROM promotions WHERE promotions.status = "pending" AND promotions.company_id = companies.id) as total')
)
->leftJoin('companies','companies.supplier_id','=','suppliers.id')
->leftJoin('company_sub_categories','company_sub_categories.id','=','companies.sub_category_id')
->leftJoin('company_categories','company_categories.id','=','company_sub_categories.company_category_id')
->groupBy('suppliers.id', 'suppliers.created_at', 'suppliers.first_name','suppliers.last_name',
'suppliers.phone','suppliers.email','suppliers.status','suppliers.image_path','companies.name','companies.id','companies.name','company_categories.title')
->orderBy('suppliers.id','DESC');
return Datatables::of($suppliers)
->add_column('next_payment_date', function($suppliers){
return date(config('constant.DATE_FORMAT'), strtotime($suppliers->created_at));
})
->filter(function ($query) use ($request) {
if (@$request->search['value']) {
$query->where('suppliers.email', 'like', "%{$request->search['value']}%")
->orWhere('companies.name', 'like', "%{$request->search['value']}%")
->orWhere('company_categories.title', 'like', "%{$request->search['value']}%")
->orWhere('suppliers.id', 'like', "%{$request->search['value']}%");
}
})
->make(true);
私のjs
$(function() {
oTable = $('#supplier').DataTable({
"processing": true,
serverSide: true,
"pageLength": 25,
ordering: true,
searching: true,
"sDom":"tpr",
"dom": 'difrtp',
ajax: '{!! route('get-supplier') !!}',
columns: [
{ data: 'name', name: 'name' },
{ data: 'email', name: 'email' },
{ data: 'title', name: 'title' },
{ data: 'created_at', name: 'created_at' },
{ data: 'status', name: 'first_name' },
{ data: 'next_payment_date', name: 'next_payment_date' },
{ data: 'action', name: 'action' }
]
});
}
コマンドによる注文があります。 すべての並べ替え機能を上書きします。 それを削除して、結果にコメントしてみてください。
->orderBy('suppliers.id','DESC');
解決しました。 ありがとう@ChaosPower
私はこのクエリで同じ問題を抱えていました:
return self::select($select)
->where('language', app()->getLocale())
->leftJoin('content_translations', 'content_translations.content_id', 'contents.id')
->latest();
最後にget()関数を追加して変更しましたが、これで問題も解決しました。
return self::select($select)
->where('language', app()->getLocale())
->leftJoin('content_translations', 'content_translations.content_id', 'contents.id')
->latest()
->get();
最も参考になるコメント
コマンドによる注文があります。 すべての並べ替え機能を上書きします。 それを削除して、結果にコメントしてみてください。