
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYour code is almost correct! The method you're looking for is defaultOrdering() instead of ordering(). Here's the fix:
.child(
S.documentTypeList('article')
.title('Artikler efter sidevisninger')
.filter('_type == "article"')
.defaultOrdering([
{field: 'views', direction: 'desc'}
])
)The key differences from your code:
defaultOrdering() instead of ordering()by and title properties)field and direction propertiesSo the correct pattern is:
.defaultOrdering([
{field: 'fieldName', direction: 'desc'} // or 'asc'
])You can also specify multiple ordering criteria if needed:
.defaultOrdering([
{field: 'views', direction: 'desc'},
{field: 'title', direction: 'asc'}
])This will order your articles by views in descending order (highest views first) in your desk structure. The defaultOrdering() method is part of the Structure Builder API and works with both S.documentTypeList() and S.documentList().
One gotcha to be aware of: If you select a custom sort order manually in the Studio UI, it will override your defaultOrdering configuration and save that preference to local storage. If your configuration doesn't seem to be working, try clearing your browser's local storage or testing in a different browser.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store