How to control entity titles in Sanity (e.g., "row 1", "row 2")?
You're looking for preview configuration in Sanity! This controls how documents and objects appear in lists throughout the Studio.
By default, Sanity tries to automatically generate preview titles from your document fields, which can result in those strange names you're seeing. You can take full control using the preview property in your schema.
Here's how to set up basic preview configuration:
{
name: 'row',
type: 'object',
preview: {
select: {
title: 'name', // Use the 'name' field as the title
subtitle: 'description'
}
}
}If you need custom logic (like combining multiple fields or formatting), use the prepare function:
preview: {
select: {
firstName: 'firstName',
lastName: 'lastName'
},
prepare({firstName, lastName}) {
return {
title: `${firstName} ${lastName}`,
subtitle: 'Customer'
}
}
}For your specific case of wanting "Row 1", "Row 2" numbering, this is trickier since the standard preview configuration doesn't have built-in access to the array index. You have a few options:
- Add an explicit number field to your row object and use that in the preview
- Use a custom input component that can access the array context and display custom numbering
- Set up an initialValue function that automatically numbers rows as they're created
The simplest approach is option 1 - add a field to store the row number:
{
name: 'row',
type: 'object',
fields: [
{
name: 'rowNumber',
type: 'number',
hidden: true,
readOnly: true
},
// your other fields
],
preview: {
select: {
rowNumber: 'rowNumber'
},
prepare({rowNumber}) {
return {
title: `Row ${rowNumber || '?'}`
}
}
}
}You can read more about this in the official preview configuration documentation and check out this guide on creating richer array item previews for more advanced examples.
Show original thread5 replies
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.