#How to sort using readByQuery with SDK
1 messages · Page 1 of 1 (latest)
Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please make sure your question includes the following:
- An explanation of exactly what you're trying to achieve.
- Any and all related code or previous attempts.
- The exact issue or error you are facing.
- Any screenshots if applicable.
When you're done with this thread, please close it.
(If you have a support agreement and need help, please contact the core team via email.)
You can use all the Global Parameters with the SDK as well
https://docs.directus.io/reference/query.html#sort
So assuming you've got a field date_published
await directus.items('articles').readByQuery({
sort: [-date_published]
});
Add - for descending order
REST and GraphQL API documentation to run queries in Directus.
Not sure how you've implemented your types but the call should work fine assuming you have a date_pubished field within your collection
i don't have type declarations, as I would have assumed the SDK did for defaults
here is how this collection is modeled
I changed y query to "-date_created" and still have the same error
This seems to only give me a "Sort" field to use
that doesn't seem helpful
Does the actual call work though?
On the type issues check out this doc https://docs.directus.io/reference/sdk.html#typescript
The JS SDK provides an intuitive interface for the Directus API from within a JavaScript-powered project (browsers and Node.js). The default implementation uses Axios for transport and localStorage for storing state.