5

I have a set of documents and I want editors to be able to choose the order they appear. I haven't been able to find any information about this. Is there a standard or built-in way to handle this in Sanity, or a plugin?

I could add a sortOrder field to the document but editors would have to fill in numbers. Inserting a document early in the list would mean manually incrementing each document after it.

I've tried creating a singleton document with a field that has type: 'array', of: [{ type: 'reference', to: [{ type: 'myType' }] }]. This does work but it seems like a workaround and doesn't make for a good editor experience. You have to create a new doc then go to this singleton doc and add it there too. It also seems to query more slowly.

Any advice? Is there already a nice way to do this that I missed?

1 Answer 1

2

Currently, your best out-of-the-box option is what you suggest: Create a singleton which has an array of references to the documents you want ordered. But as you point out, this will require new documents to be added manually in a separate context. Which amounts to a clunky user experience.

On the deep end of the pool, you could create a custom input component which allows the order be controlled from within any orderable document, but persists that order (automatically, under the hood) to a singleton.

If you end up with the latter solution, it would be totally awesome if you could share the result. There are several others who have been looking for a solution to the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.