eZ Platform Discussions

Infinite ajax scroll pagination of a list of content


#1

Hi, i want to implement a infinite ajax scroll pagination. I want to create a special route (rest api) to retrieve my objects in json format (with pagination params).
What is the best way to achieve that?
May be i could use the ezplatform rest api, but i want to get fields on my objects and i’ve not seen how to do that…
Thanks


#2

Hello.
You could use Search Service exposed via REST API /views endpoint. For example to query for all direct children of Home folder you could perform the following REST query:

POST /api/ezp/v2/views HTTP/1.1
Host: <your eZ Platform Host>
Content-Type: application/vnd.ez.api.ViewInput+json; version=1.1
Accept: application/vnd.ez.api.View+json

{
    "ViewInput": {
        "identifier": "<your-unique-identifier>",
        "public": false,
        "ContentQuery": {
            "Filter": {"ParentLocationIdCriterion": 2},
            "SortClauses": {},
            "Query": {},
            "limit": 10,
            "offset": 0
        }
    }
}

Notice that:

  • input format is controlled by Content-Type header (I’m telling REST server that I’m gonna send ViewInput in JSON format (XML is also available)).
  • output format is controlled by Accept header (I’m telling the server that I need View output in JSON format - again - could be also XML).

About the payload:

  • identifier is arbitrary, but recommended to be unique per query parameters
  • ContentQuery is the one that will return all Fields of found Contents (the other one is LocationQuery).
  • Filter is the key part, it’s what you’re searching for using search Criteria. It does not influence score.
  • Query is almost the same as Filter but influences score.
  • ParentLocationIdCriterion contains Location Id of a parent (2 for Home folder). There are many more Criterions depending on your needs.
  • Pagination can be controlled by limit and offset.
  • SortClauses can be used to sort the result.

However, there is one disadvantage of using that endpoint for extensive querying. It is POST request because it requires payload as a request body. That means it is not cached. So for your use case I believe custom endpoint performing search based on GET parameters would be better.
If you want to extend REST API to add your endpoint you can follow Extending REST API doc.

Let me know if you have more questions about that.

Kind regards,
Andrew Longosz
eZ Systems


#3

Hi @hufon!

We implemented such a feature on ezplatform.com (blog and bundle list). The code is public, please have a look!

Cheers!