๋ฐ๋ฅ ๊ธ ์ด์ ์์ฝํ๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?
$dataTableQuery = Users::query()
->leftJoin('user_info', 'users.id', '=', 'user_info.id')
->select([
'users.id',
'users.username',
'users.role_id',
'user_info.first_name',
'user_info.last_name',
'user_info.email',
'users.blocked',
'users.balance',
'users.created',
]);
$sums = [
'sum_balance' => '0',
];
$datatables = Datatables::of($dataTableQuery )
->escapeColumns(['first_name', 'last_name', 'email'])
->editColumn('created', function ($user) {
return Carbon::createFromFormat('Y-m-d H:i:s', $user->created)->toDateString();
})
->editColumn('blocked', function ($user) {
return $user->blocked_label;
})
->addColumn('actions', function ($user) {
return $user->gamers_buttons;
})
->filter(function ($query) use ($request) {
if ($request->has('username')) {
$query->where('username', 'like', "%{$request->get('username')}%");
}
})
->addSum('sum_balance', DB::raw("sum(balance)")) <-- How do it?
->with('sums', $sums);
->
๋ค์๊ณผ ๊ฐ์ด DT์ ์ ๋ฌ ๋ ๋์ผํ ์ฟผ๋ฆฌ๋ฅผ ์ฌ์ฉํฉ๋๋ค.
->with('sum_balance', $dataTableQuery->sum('balance'))
$ dataTableQuery-๋ฐ์ดํฐ๋ฅผ ํํฐ๋งํ๊ฑฐ๋ ๊ฒ์ํ์ง ์๊ณ ์ ๋ฌ๋ฉ๋๋ค. ๋ชจ๋ ๋ฐ์ธ๋ฉ ๋งค๊ฐ ๋ณ์๋ก ๊ตฌ๋ฌธ ๋ถ์ ๋ ์ฟผ๋ฆฌ๋ฅผ ์ป๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?
๋ธ๋ ์ด๋์ ์ด๊ฒ์ ํ์ํ๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?
@ yurik3zzz ์ต์ ๋ฒ์ ์์ withQuery api๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
@ prakash-pokhrel ajax ์๋ต ๋ฐ์ดํฐ์ ์ก์ธ์คํ์ฌ ์๋ฐ ์คํฌ๋ฆฝํธ๋ฅผ ํตํด ๋์คํ๋ ์ด๋ฅผ ์ฒ๋ฆฌํด์ผํฉ๋๋ค. ์ : LaravelDataTables["users-table"].ajax.json()
@yajra ๋๋ ์์ง๋ ๊ทธ๊ฒ์ ์ป์ง ๋ชปํ๋ค. ์ด๊ฒ์ datatable์ html () ํจ์ ์์ ๋ฃ๊ฑฐ๋ ๋ธ๋ ์ด๋์ ์ง์ ๋ฃ์๊น์? Btw, ๋๋ datatable์ ์๋น์ค๋ก ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
drawCallback์ ์คํฌ๋ฆฝํธ๋ฅผ ์ถ๊ฐํด๋ณด์ธ์.
```js
$ ( '# users-table'). on ( 'draw.dt', function () {
$ ( '# total'). val (LaravelDataTables [ "users-table"]. ajax.json (). total)
})
์ต์ html ํจํค์ง v4.0์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ด ํ ์ ์์ต๋๋ค.
public function html()
{
...
->ajax()
->drawCallback('function() { $("#total").val( this.api().ajax.json().total ) }')
...
์๋
ํ์ธ์,
"#total"์ ๋ฌด์์ ์๋ฏธํฉ๋๊น?
-> drawCallback ( 'function () {$ ( "# total"). val (this.api (). ajax.json (). total)}')
์ด ID๊ฐ ํ ์ด๋ธ ๋ด๋ถ ๋๋ ๋ค๋ฅธ HTML ์์์ ์์ต๋๊น?
id๋ฅผ ์ฌ์ฉํ๋ ์์์ ๋ํ jquery ์ ํ๊ธฐ์ ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
$ dataTableQuery-๋ฐ์ดํฐ๋ฅผ ํํฐ๋งํ๊ฑฐ๋ ๊ฒ์ํ์ง ์๊ณ ์ ๋ฌ๋ฉ๋๋ค. ๋ชจ๋ ๋ฐ์ธ๋ฉ ๋งค๊ฐ ๋ณ์๋ก ๊ตฌ๋ฌธ ๋ถ์ ๋ ์ฟผ๋ฆฌ๋ฅผ ์ป๋ ๋ฐฉ๋ฒ์ ๋ฌด์์ ๋๊น?