Paging logic with angular and mysql

1

I would like to know how to implement a paging logic in the database using mysql and angular on the front end with ui-bootstrap or dirPagination. For example, getting 10 in 10 on the bank using LIMIT and OFFSET . My question is in the implementation of logic on the front end. It can be a simple explanation and some example.

As an API, I have doubts about endpoints as well. Would they look like the examples below? I would like an example too.

GET /recursos?offset=10&limit=10
GET /recursos/limit/:limit/offset/:offset
    
asked by anonymous 07.11.2016 / 11:31

1 answer

2

I usually use these parameters as query params so they are optional and I always return with a default value if no parameter is passed, type 1st page with 10 items.

GET /recursos?pagina=1&total=10

Receiving these parameters in the back, do:

int offset = (pagina < 1 ? 0 : pagina-1) * total;
int limit = offset + total

Remember to return the total amount of items in the bank, making a COUNT with no limit and offset for your front to know how much it can still order back.

A good component that already solves this on the front is ngTable , where you only need to tell which current page, the total items that can be returned and quantities and items per page.

    
07.11.2016 / 12:17