How to display data in tabular form in Sanity Studio preview pane
18 replies
Last updated: Jul 2, 2021
S
Hi, In the preview section of sanity studio, I want to display the all the fields' data in tabular form of all the published documents of one document type. (example all customer's data of type customer document should be in table in preview section)So every row in the table refers to one document and when I click that row in preview it open the edit mode of document where I can edit and publish. Any suggestions would be greatly appreciated, Thank you (edited)
Jul 2, 2021, 10:59 AM
S
Have you tried anything yet? What was the error?
Jul 2, 2021, 12:47 PM
S
no I havent tried, as there is not much info on this type in sanity docs
Jul 2, 2021, 12:49 PM
S
do you have any idea how to do this?
Jul 2, 2021, 12:49 PM
S
I don't either. But the preview pane is where can insest our own thing. like any div or iframe. So I guess you need to create a frontend just like any other app, then fetch the required data and display it in an HTML table.
Jul 2, 2021, 12:51 PM
S
make that front-end ready, then Some experts will help you if the data is not showing properly in the preview pane.
Jul 2, 2021, 12:52 PM
S
u mean I can use html table and get data displayed in preview pane of sanity studio?
Jul 2, 2021, 12:53 PM
S
Here's one of my preview pane looks like:
import React from "react"; import styles from "./IframePreview.css"; export default function PagePreview(props) { const { displayed } = props.document; if (!displayed?.slug?.current) { return ( <div>The product needs a slug before it can be previewed.</div> ); } const url = process.env.NODE_ENV === "production" ? process?.env?.SITE_URL && process.env.SITE_URL !== "" ? `${process.env.SITE_URL}/${displayed?.slug?.current}?preview` : `${process.env.VERCEL_URL}/${displayed?.slug?.current}?preview` : `<http://localhost:3000/${displayed?.slug?.current}?preview>`; return ( <div className={styles.componentWrapper}> <div className={styles.iframeContainer}> <iframe src={url} frameBorder={"0"} /> </div> </div> ); }
Jul 2, 2021, 12:53 PM
S
this is preview pane of sanity studio?
Jul 2, 2021, 12:54 PM
S
Yes, that's correct, If you see the return () function in the above code, you can just put anything you want using the Props
Jul 2, 2021, 12:54 PM
S
Yes, preview pane is something we make ourselves, so we can do anything we want.
Jul 2, 2021, 12:54 PM
S
In my case, I have live preview using iframe
Jul 2, 2021, 12:54 PM
S
in your case you will be replacing it with <table> and some GROQ Queries.
Jul 2, 2021, 12:55 PM
S
check this for detailed guide and options :https://www.sanity.io/docs/structure-builder-reference#getdefaultdocumentnode-97e44ce262c9
Jul 2, 2021, 12:56 PM
S
kind of okay, but in preview when i display the doc's details in table forms and each row should refer to one doc and that row's columns should have doc fileds data . And when i click each row it should open the corresponding document in editor form . Do you know how can we do this
Jul 2, 2021, 1:01 PM
S
Thanks for your help, by the way!!
Jul 2, 2021, 1:01 PM
S
I'm not sure about that, I suggest make a rough Wireframe of how you want the UI, so the Sanity Team will be able to check if possible or not.Will wait for their Reply.
Jul 2, 2021, 1:03 PM
S
Example in first pane in the list of document types lets consider we have one type customer and in this customer preview , we need to display all the cutomers and their details in table form and each row should refer to a customer doc
Jul 2, 2021, 1:03 PM
S
okay, please let me know you find anything related to this. Thank you very much!!
Jul 2, 2021, 1:04 PM
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.