External Sorting
Last updated
Last updated
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.
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"
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:
For this example, it would look like this in Xano:
Note for order by: asc = ascending desc = descending
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.
Create the fields sortBy and orderBy as regular text inputs.
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.
Then map the sortBy and orderBy paths to their respective inputs.
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.