Watch a live product demo ๐Ÿ‘€ See how Sanity powers richer commerce experiences

Is there a way to set a default sort ordering in your documents?

15 replies
Last updated: Dec 2, 2020
Is there a way to set a default sort ordering in your documents? Say if you want the list of blog posts to sort by publish date by default without forcing to user to click the options and choose a defined sort option?
Oct 15, 2020, 5:28 PM
This works fine was just wondering is there a way to set a default insted of having the user select in manually
Oct 15, 2020, 5:30 PM
Oct 15, 2020, 5:32 PM
No I looked through there an it shows you how to create a sort option which appears in the dropdown screenshot but I didnt see a way to make a custom view default without clicking the options dropdown
Oct 15, 2020, 5:36 PM
Unless Iโ€™m missing something
Oct 15, 2020, 5:37 PM
you should do the default ordering in the desk structure then
Oct 15, 2020, 5:37 PM
Ah yeah I was wondering if thats where it should go. So if you have to set the order in the deskStructure file I guess
Oct 15, 2020, 5:38 PM
OK nice thanks fro the share!
Oct 15, 2020, 5:40 PM
you're welcome ๐Ÿ™‚
Oct 15, 2020, 5:41 PM
Got it working thanks for clearing that up for me! This is my first Sanity project still trying to wrap my head around everything
Oct 15, 2020, 6:08 PM
Glad to help if you have more questions
Oct 15, 2020, 6:40 PM
this fix is for programmers. what about the end user? How do they sort the blog?
Dec 1, 2020, 7:12 PM
you can add sort options to the deskstructure like this:

  .filter('_type == "blog"')
and in your blog schema

  name: "blog",
  title: "Blog",
  type: "document",
  orderings: [
      title: "Title",
      name: "title",
      by: [{ field: "title", direction: "asc" }],
Dec 2, 2020, 6:28 AM
this is what the end users will see
Dec 2, 2020, 6:30 AM โ€“ build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Related answers

Get more help in the community Slack

TopicCategoriesFeaturedRepliesLast Updated
After adding the subtitle and running this code npm run graphql-deploy It does nothingSep 15, 2020
how to limit a reference to just one entry in Studio reference input side versus the default as-many-entries-as-you-fill-in-an-array...Sep 18, 2020
Is it possible to fetch more than one "_type" using GROQ?Nov 2, 2020
I want to add a view with the Structure builder (S.view.component) where I list similar documents based on the title. What...Sep 23, 2020
Is there a structure builder example where the format of each preview for the document list is modified?Feb 3, 2021
I have an array of references to a country schema type but it always just returns NULL values for meJan 30, 2021
Hi, I need help with a query for getting the url of an image asset. Here is what I've been trying, but I only get the _ref...Dec 1, 2020
Sanity UI looks brilliant :smiley: Is something like the current date picker possible at the moment? Iโ€™m not sure if anicon...Dec 21, 2020
Hey everyone. I have been coding and may have potentially accidentally deleted something. Does anyone know how to resolve...Dec 26, 2020
Hello everyone and happy new year :raised_hands::skin-tone-2:, I have a problem with outputting Portable Text :disappointed:...Jan 1, 2021

Related contributions

Clean Next.js + Sanity app
- Template

Official(made by Sanity team)

A clean example of Next.js with embedded Sanity ready for recomposition.

Cody Olsen
Go to Clean Next.js + Sanity app

Blog with Built-in Content Editing
- Template

Official(made by Sanity team)

A Sanity-powered blog with built-in content editing and instant previews.

Go to Blog with Built-in Content Editing