๋๋ 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();
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ช ๋ น์ ์ํ ์ฃผ๋ฌธ์ด ์์ต๋๋ค. ๋ชจ๋ ์ ๋ ฌ ๊ธฐ๋ฅ์ ์ฌ์ ์ํฉ๋๋ค. ๊ทธ๊ฒ์ ์ ๊ฑฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ๋๊ธ๋ก ๋ฌ์๋ณด์ญ์์ค.