Add filter option to @sanity/orderable-document-list

11 replies
Last updated: May 31, 2022
Hello
user T
!
I was using and testing your
@sanity/orderable-document-list. Is the Sanity team planning to add the filter option to the options list?
That would be extremely helpful, our clients are asking for this feature.
AI Update

Good news! The Sanity team has already added the filter option to the @sanity/orderable-document-list plugin. Based on the GitHub repository, this feature is now available and documented.

You can add a filter parameter when configuring the orderable document list in your Desk Structure. Here's how to use it:

orderableDocumentListDeskItem({
  type: 'project',
  title: 'Projects',
  // Add your filter here
  filter: `__i18n_lang == $lang`,
  params: {
    lang: 'en_US',
  },
  S,
  context,
})

The filter works with GROQ query syntax and accepts parameters through the params option. This is particularly useful for scenarios like:

  • Filtering by language in internationalized content
  • Showing only published/draft documents
  • Filtering by categories or tags
  • Any other GROQ-compatible filter condition

Important caveat to be aware of: While the filter controls which documents are displayed in the list, the order ranks are still computed based on all documents of that type. As noted in the README:

However, order ranks are still computed based on all documents of the same type. Creating multiple lists with different filter settings could produce unexpected results.

So if you create multiple orderable lists with different filters for the same document type, you might see unexpected ordering behavior since they're all sharing the same orderRank field values.

The feature is available in the current version of the plugin, so make sure you're running an up-to-date version to access this functionality. You can check the releases page for version history.

Show original thread
11 replies
I think that the best way to do these things for now is with Custom Inputs, since you have full flexibility.
Hey!
That would be useful – but I haven’t fully considered the impacts of setting orders for documents when some documents have been filtered out? It’s currently “safer” to show all documents since the order is established across the entire
_type
, not a filtered subset of the
_type
I understand. I think that filtering is useful when you have i18n in place.For instance, I have document of type page that are localized, and I would like to show the pages that are in the base language. Currently, I would see all the pages.
I understand that this is a specific use case, we use Sanity as CMS for our websites and displaying all the pages in all locales might be overwhelming for our clients.
Ah. Now that is interesting.
Yes, If I can help you with any information please let me know. We use Sanity intensively and we would be really happy to contribute on this.
Have been involved a bit in our i18n efforts of late and think it's a perfect use case.
You could put together a PR if you're feeling ambitious, otherwise I'll add it to my todo list
😄
You got it! I’ll do my best, but I think I won’t have any company time for this PR. I would be extremely happy to review or test it though.I’ll keep an eye on the repo then
😉
Thanks to
user M
you can now add a
filter
in
0.0.9
🎉

https://www.npmjs.com/package/@sanity/orderable-document-list
I’ll test it right away User, in the next days I will give it a shot 🙂 Looking forward to testing it!
I’ve implemented everything as reported on the readme file, and it works like a charm 🙂
Some feedbacks after some hours of usage:• when I delete an element, I still get the element on the list with title “Untitled”
• If I create a new element, it’s not shown on the list
In both case, I have to reload the page to see the changes

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.

Was this answer helpful?