shopwareshopware6shopware6-apishopware6-app

Shopware 6 App with Symfony ServerApp - Pagination example


I need to use pagination because getting all orders through "/api/search/order" is resulting in a 500 error when there are too many orders. I am making a axios request inside a vue template that gets all orders. Thats what I currently use for selecting the orders:

data: {
 associations: {
  documents: {
   associations: {
    documentType: {}
   }
  }
 },
 includes: {
  order: [ 'orderNumber', 'documents' ],
 }
}

I know that there are the properties limit and page, but how can I use these inside of my symfony app with a jquery datatable which uses a vue template? Are there any examples available on how to implement pagination? Couldnt find anything in the docs. :(


Solution

  • You already gave yourself half of the answer with the limit and page properties. In addition you should set total-count-mode to 1 to get the total number of records regardless of the offset/limit, as you will likely need it for your pagination.

    {
        "page": 1,
        "limit": 5,
        "total-count-mode": 1
    }
    

    This should give you everything you need to handle pagination client-side. The implementation then entirely depends on the library you're using. As for datatables there are numerous examples on here and the web in general how to handle pagination with server-side sources. The library may have their own parameters for pagination set in stone so you may have to translate them before the request. Furthermore they might work with offsets instead of pages, which you could get by multiplying the page with the limit and subsequently subtracting the limit once.

    You likely have better chances of getting an answer by asking a question tagged with jquery/datatables without mentioning Shopware, as at that point that's out of scope and you likely just need to know how to translate those parameters.