External Sorting

To use external sorting, you need a JSON array that defines the sort in the following format. The object can either be constructed by your front-end and provided to Xano via a JSON input, or your front-end can just send the sort parameters and you can construct the array in the function stack with a Create Variable function.

You can copy the JSON below and paste it into the value of a Create Variable step, and then choose "Import JSON" on the pop-up that displays to let Xano construct this for you automatically.

[
      {"orderBy": "","sortBy": ""}
    ]

You can define multiple sorts by adding additional objects to the array.

orderBy will either be 'asc' or 'desc' for ascending or descending order

sortBy will contain the table name and the column name to sort by. As an example, if you have a table called "transactions" and you want to sort by the column "amount", your sortBy would be "transactions.amount"

Classic Mode (deprecated)

How do I use the External query to sort?

First, you must create an Input that is a JSON data type.

Next, link the configuration in the External query tab to the JSON input using the drop down menu. Additionally, select which permissions you want to grant for external use.

Finally, we are ready to use the external query to sort. In order to sort, we must enter in the JSON input in the following format:

{
  "external": {
    "sort": [
      {"sortBy": "","orderBy": ""}
    ]
  }
}

For this example, it would look like this in Xano:

Note for order by: asc = ascending desc = descending

Alternate 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.

Step 1

Create the fields sortBy and orderBy as regular text inputs.

Step 2

Add a new Function Stack item: Create Variable

Paste the JSON object into the input line and hit import JSON. Or create the object manually using the set filters.

{
  {
    "sort": [
      {"sortBy": "","orderBy": ""}
    ]
  }
}

Then map the sortBy and orderBy paths to their respective inputs.

Step 3

Reorder your Create Variable function so that is before the Query All Records function. Then navigate to the External tab within the Query All Records and map it to the variable.

Last updated