๐Ÿ”ฎ Sanity Create is here. Writing is reinvented. Try now, no developer setup

Building a custom dashboard widget to display data within Sanity Studio using groq queries.

10 replies
Last updated: Jul 29, 2022
Hi there, I'm looking to build a dashboard widget to display some content within the sanity studio of a website I'm building, rather than the front end.I'm looking for some boilerplate code where I can run a groq query and then output some data. A simple example could be fetch all of the titles of all of the posts and display them inside of an unordered list within the dashboard widget. Is anyone able to point me in the right direction?
Jul 28, 2022, 9:49 PM
Which language? So you want to build this outside of the Sanity Studio, right?
Jul 28, 2022, 9:51 PM
Javascript - I am looking to build a dashboard widget to show some data - So within Sanity studio like in the screenshot below. So really just some boilerplate code of how to run a basic groq query and display some data it in this location
Jul 28, 2022, 9:58 PM
I don't know of any, but take a look at this one (or any of the code shared through the Sanity exchange: https://www.sanity.io/plugins/documents-pane
Jul 28, 2022, 10:18 PM
Great, I'll take a look thanks ๐Ÿ™‚
Jul 28, 2022, 10:27 PM
user L
is right, that this will work within the desk as a view (so itโ€™s a plugin for the structure builder), but if you want something for the Dashboard, you could try this here: https://www.sanity.io/plugins/sanity-plugin-dashboard-widget-document-list ๐Ÿ™‚
Jul 29, 2022, 8:39 AM
user J
thanks for the message. I've looked into the document list plugin - as far as I know it doesn't look like it will provide what I'm looking for here. I'm looking for something a bit more custom.
To provide a bit more context I have a sanity powered website where users can confirm if they are going to an event or not. So users can view their invitation and submit a form which posts an 'rsvp' with either 'yes' or 'no' selected and also the names and guests they will be brining as well as some other details such as special dietary requirements, if they are interested in certain transport options. So I'm looking to build a widget which maps over all of the RSVPs and output the current list of guests attending - it would be great for an MVP just to list the total number of guests who have said they're going to attend the event - but I would like to expand on it further - such as to display an unordered list all the names or maybe a table of all the important data I'll need as part for the admin side of the event.

So I'm looking for a way to output all of this data somewhere inside of the studio - it definitely doesn't need to be the dashboard but I figured that might be a good place. If anyone can figure out what I'm trying to do and suggest an approach that could get the job done I'm really interested.
Jul 29, 2022, 9:55 AM
Well in that case, you would have to write a custom widget yourself, but you could checkout this existing one and use itโ€™s code as a boilerplate.Use a more in depth query for your needs instead of
and our wonderful Sanity UI and you should be able to do so pretty quicklyWhat do you think?
Jul 29, 2022, 10:12 AM
user J
- glad you clarified that
was the query - I think I previously looked at this plugin and overlooked that! This is exactly what I need. Thanks again for your help ๐Ÿ˜€
Jul 29, 2022, 11:01 AM
Wonderful! (and yes, not everyone can spot the GROQ methods and a hint can make the difference ๐Ÿ™‚)You might consider sharing your code later on our
exchange and help others with similar concerns!
Jul 29, 2022, 11:10 AM

Sanityโ€“ build remarkable experiences at scale

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

Was this answer helpful?