Datatables๋ฅผ ์๋น์ค๋ก ์ฌ์ฉํ ๊ณํ์ด๋ฉฐ ํ์, ํธ์ง ๋ฐ ์ญ์ ์ด์ ์ถ๊ฐํด์ผ ํฉ๋๋ค. ๋ฌธ์(http://datatables.yajrabox.com/eloquent/add-edit-remove-column)์์ ์์ ๋ฅผ ์ฐพ์์ง๋ง 'Datatables as Service'์ ๋ํ ์์ ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค.
๋ค๋ฅธ ๋ฌธ์ ์์ ์๋ฃจ์ ์ ์ป์์ต๋๋ค.
public function ajax() {
$query = $this->query();
return $this->datatables
->eloquent($this->query())
->addColumn('action', function ($query) {
return '<a href="' . route("admin.districts.edit", $query->id) . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
})
->make(true);
}
์๋ ํ์ธ์ Yajra, ๋ค๋ฅธ ์ด์ ์ญ์ ๋ฐ ํธ์ง ๋ฒํผ์ ์ถ๊ฐํด์ผ ํ์ง๋ง ํ๋์ ์ด๋ง ์ฌ์ฉํ๋ ์์ ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ๋ด๊ฐ ๋ญ ๋ณด์ฌ?? ๋์์ฃผ์ธ์
๋ค๋ฅธ ๋ฌธ์ ์์ ์๋ฃจ์ ์ ์ป์์ต๋๋ค.
public function ajax() { $query = $this->query(); return $this->datatables ->eloquent($this->query()) ->addColumn('action', function ($query) { return '<a href="' . route("admin.districts.edit", $query->id) . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>'; }) ->make(true); }
์ด ์์ ์ ์ํํ ๋ ์์ HTML์ ์ธ์ํ๋ ์ฌ๋์ ์ํด HTML์ด ์ด์ค์ผ์ดํ๋๋ ๊ฒ์ ๋ฐฉ์งํ๊ธฐ ์ํด rawColumns('action')๋ ์ถ๊ฐํด์ผ ํ์ต๋๋ค. ์:
public function ajax() {
$query = $this->query();
return $this->datatables
->eloquent($this->query())
->addColumn('action', function ($query) {
return '<a href="' . route("admin.districts.edit", $query->id) . '" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i> Edit</a>';
})
->rawColumns(['action'])
->make(true);
}
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค๋ฅธ ๋ฌธ์ ์์ ์๋ฃจ์ ์ ์ป์์ต๋๋ค.