External Paging

Using Simple Mode for external paging, you can easily set variables or values for the following options as pertains to paging:

  • Page The current page of results

  • Per Page The amount of results per page

  • Offset Offset is available if you need to manually define an offset for the set of records returned. The following example, assuming your record IDs start at 1, will return records 1 - 10 Page: 1 Per Page: 10 Offset: 0 The following example, assuming your record IDs start at 1, will return records 2 - 11 Page: 1 Per Page: 10 Offset: 1

To define your external parameters using simple mode, just specify your desired values or variables in the External tab:

Classic Mode (deprecated)

How do I use the external query to allow for paging override?

First, create an input that is a JSON data type.

Secondly, open the Query all Records function. In the Output tab, under return enable paging.

Next, link the configuration in the External query tab to the JSON input using the drop down menu. Additionally, select "Allow Page Override" and "Allow Per Page Override" permission. (Note: you can choose just one between Page Override and Per Page Override or both. Determine what works best for your use case).

Now, we are ready do paging by the external query. Because the external query takes a JSON input, we must format the input in a JSON like the examples below.

In this example, "external" is the name of our JSON input. It is not required as part of the input but used as an example name.

The below JSON object uses both Page Override and Per Page Override. It will return page 1 and 2 items per page:

{
  "external":{"page":1, "per_page":2}
}

The below JSON input would be used for just Page Override:

{
  "external":{"page":1}
}

The below JSON input would be used for just Per Page Override:

{
  "external":{"per_page":2}
}

Alternative to JSON input

Front-ends can sometimes have limitations as far as the data you are able to pass as an input. Fortunately, Xano is super-flexible to allow you to workaround these limitations. If you are having issue passing a JSON object as an input in your front-end then you can create the object in the Function Stack as a variable and make it dynamic with scalar inputs.

This method is also handy if you want to use page and per page as query and URL parameters.

Step 1:

Create inputs "page" and "per_page" as integer input types. (Or if you are just using one of the overrides use just that one).

Step 2:

Add a Create Variable Function to your Function Stack and drag it to the top. Create the following JSON structure using the SET filter or import JSON action.

{
"page": "",
"per_page": "1"
}

Then, choose the inputs as the values for the corresponding paths:

Step 3:

Ensure paging is enabled on the output tab of Query All Records.

Then, on the External tab map the variable you created to the By External Query dropdown and select Allow Page Override and Allow Per Page Override. (If you are only using one then just select that one).

Click save and you're ready to go.

Last updated