Applying arbitrary order to documents in Sanity using reference fields and custom ID generation
Good news! There's an official plugin that solves exactly this problem: @sanity/orderable-document-list.
This plugin gives you drag-and-drop ordering directly in the Studio editing interface, so you don't have to manually fiddle with number fields anymore. It's maintained by the Sanity team and works by adding an orderRank field to your documents behind the scenes.
Installation:
npm i @sanity/orderable-document-listThe plugin is designed for Studio v3 (for Studio v2, you'd need the @studio-v2 tag, but that's deprecated now). You can find the full setup instructions in the GitHub README.
Why this is better than a manual order field:
- No more manually adjusting numbers when you want to reorder
- Drag-and-drop interface is way more intuitive for content editors
- The ordering persists and can be queried from your frontend
- Handles the complexity of maintaining order ranks automatically
Alternative approaches (if the plugin doesn't fit your use case):
- Create a singleton document with an array of references to control order
- Use wrapper documents containing reference arrays
- Stick with the numerical order field approach (though as you've found, it's tedious)
The orderable document list plugin works great for small to medium-sized collections where manual ordering makes sense. For very large datasets, you might want to consider query-based sorting instead.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.