Discussion on the use of tables in Sanity UI and why they may be an anti-pattern.
7 replies
Last updated: Mar 12, 2021
Is there some component or styling for HTML tables in sanity-ui? I guess not, but I just wanted to be sure. Otherwise I'll go with react-table.
Mar 5, 2021, 3:37 PM
we tend to avoid table components (and styling of HTML), because they often are a structured content anti-pattern - but there are a couple of plugins around.
Mar 5, 2021, 3:49 PM
user Y
Do you have any references that explains why it is often an anti-pattern?Mar 9, 2021, 2:53 PM
A table is essentially an array of objects containing arrays, so the first array may be "rows" containing an object with an array of "cells" for that row. Adding a "column" in this case means adding an extra cell to the nested array of each row - always in the same position.
I guess one reservation around tables may come from the 'obligation' to keep the nested arrays in sync between the different rows to keep the table intact, which could give its challenges when updating through the HTTP API or when dealing with complex objects inside of cells.
I guess that doesn't fully explain why it would be an anti-pattern though
🙂
I guess one reservation around tables may come from the 'obligation' to keep the nested arrays in sync between the different rows to keep the table intact, which could give its challenges when updating through the HTTP API or when dealing with complex objects inside of cells.
I guess that doesn't fully explain why it would be an anti-pattern though
🙂
Mar 9, 2021, 4:38 PM
1. Often people use tables for layout control. But make the data / content less accessible/queryable and are moving presentation concerns into the content model2. What one often wants is a
table view for typed data (array of named objects). But these table plugins, as Peter points out, gives you generic matrix data.Take our API reference docs. There's a bunch of tables there in the frontend, but in the backend it's arrays of objects that describes API methods as typed fields. That means we can query in much more sophisticated and directed ways than if we had those as generic tables.
table view for typed data (array of named objects). But these table plugins, as Peter points out, gives you generic matrix data.Take our API reference docs. There's a bunch of tables there in the frontend, but in the backend it's arrays of objects that describes API methods as typed fields. That means we can query in much more sophisticated and directed ways than if we had those as generic tables.
Mar 9, 2021, 4:42 PM
user Y
oh! now I understand your first reply. I should have been more specific: I wasn't building a custom form input, but a new screen inside the Studio where I display data in forms of graphs and tables. So yes, I totally agree with you on the notion of table view!In the meantime, I finished coding the table and I'm quite happy with the result, knowing this is my first "project" with React 😋Here's the code:
https://github.com/mornir/terminofeu-studio/blob/master/plugins/entries-stats/ApprovalTable.js
Mar 11, 2021, 8:42 PM
user E
– there are no primitives for building graphs/trees/sheets/tables yet, but will def consider it. It may be possible to use @sanity/uiin combination with some other libraries, since
@sanity/uiconsists mainly of very small building blocks / components.
Mar 12, 2021, 3: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.