✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

How to display data in tabular form in Sanity Studio preview pane

18 replies
Last updated: Jul 2, 2021
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
Have you tried anything yet? What was the error?
Jul 2, 2021, 12:47 PM
no I havent tried, as there is not much info on this type in sanity docs
Jul 2, 2021, 12:49 PM
do you have any idea how to do this?
Jul 2, 2021, 12:49 PM
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
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
u mean I can use html table and get data displayed in preview pane of sanity studio?
Jul 2, 2021, 12:53 PM
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
this is preview pane of sanity studio?
Jul 2, 2021, 12:54 PM
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
Yes, preview pane is something we make ourselves, so we can do anything we want.
Jul 2, 2021, 12:54 PM
In my case, I have live preview using iframe
Jul 2, 2021, 12:54 PM
in your case you will be replacing it with &lt;table&gt; and some GROQ Queries.
Jul 2, 2021, 12:55 PM
Jul 2, 2021, 12:56 PM
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
Thanks for your help, by the way!!
Jul 2, 2021, 1:01 PM
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
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
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.

Was this answer helpful?