Laravel Pagination
joeljerushan opened this issue · 18 comments
Is it possible to Paginate Laravel Paginate feature with vue2-datatable ? my return view like following i would like to paginate this with this plugin ..
{
"current_page": 1,
"data": [
{
"id": 1,
"bill": "62753",
"type": 3,
"amount": 58,
"price": 107,
"date": "2018-06-09",
"stock": 0,
"created_at": null,
"updated_at": null
},
{
"id": 2,
"bill": "97246",
"type": 5,
"amount": 150,
"price": 118,
"date": "2018-05-28",
"stock": 1,
"created_at": null,
"updated_at": null
}],
"first_page_url": "http://site.test/purchases/get/list?page=1",
"from": 1,
"last_page": 25,
"last_page_url": "http://site.test/purchases/get/list?page=25",
"next_page_url": "http://site.test/purchases/get/list?page=2",
"path": "http://site.test/purchases/get/list",
"per_page": 2,
"prev_page_url": null,
"to": 2,
"total": 49
}
just write some convert functions
query = { limit: 10, offset: 0, sort: '', order: '' }
total = 0
by default
@kenberkeley any suggestions ? or documentation for custom pagination urls for now total
is working fine. its kinda server side pagination
according to the return view you provided, query.limit
is per_page
which is 2
, query.offset
is (current_page - 1) * per_page
which is 0
, total
is 49
that's fine but what about processing with next previous pages ?
define next previous pages
And how I can filter data on server side?
that's your business logic, pal
@kenberkeley i'm confused about defining next
previous
pages can you show me documentation url or example here ?
@joeljerushan : that's fine but what about processing with next previous pages ?
so i was confused what is next previous pages
i was talking about "next_page_url": "http://site.test/purchases/get/list?page=2",
server side processing to get next set of data and previous set of data.
Hope you understand
control everything on the front end might be better
i understood ! but what if we get large set of data :) that will take time to load json object right
so you got to make the pagination
Thank you :) link you posted helped me ;)
Hi,
It seems that I cannot get the vue2-datatable pagination links working properly.
I'm a vue newbie and literally stucked on this test project since weeks... I cannot understand if it depends on vue or laravel side.
I'm sending to the rest api call these parameters:
methods: {
getIncarichi() {
axios.get("api/incarico2", {
params: {
limit: this.query.limit,
offset: this.query.offset,
sort: this.query.sort,
order: this.query.order,
}
})
.then(response => {
this.data = response.data.data;
this.total = response.data.total;
})
.catch(error => {
console.log(error);
});
}
},
But the paginator is always setting up the page 1 response.
This is laravel code
public function index2(Request $request)
{
$data = $this->model->getModel()
->orderBy($request->sort, $request->order)
->paginate($request->limit);
return response()->json($data);
}
Example:
Clicking on the links (page 2 in this case) is always returning page 1 results using server-side laravel LengthAwarePaginator
Here is the debug screenshot of $data object been built
And the table isn't refreshed.
(column sorting, column filtering and items per page limits are working correctly).
Could please someone point me to the right direction?
Thank you,
Alex