I’ve been trying to create a table in Sketch using smart layout. My goal is to have a symbol for a column (to build tables with) that automatically resizes based on content, while having a number of different symbols that can be used for the cells.
So far I’ve been unsuccessfull in making the column resize as a whole. It only resizes the cell. My best attempt was to:
1 create a symbol for the table cell: a rectangle with a text field set on ‘auto width’
2 create a symbol for the table column with the cell symbols
3 add auto layout (horizontal left to right) to both the cell symbol and the column symbol
4 I checked ‘Adjust content on resize’ for the column as well (not sure if that matters at all)
5 none of the elements are pinned in any way
What I end up with is a column that only resizes the cell when adding larger content, not the rest of the column. It seems like it ‘prioritizes’ the layout of the cell (which is related to the text content of that cell) and doesnt care about the layout of the column.
Is there a solution for this?
Hi @Rickvanthof, welcome to the Forum
Thanks for sharing this use case! We’ll look into it and post an update here.
This is a fine timing! We’ve just rolled out this post about the latest improvements in Smart Layout, so if you have any other use cases, please feel free to post them there
@Rickvanthof I have experience in this, so can share what I believe to be a best practice.
First, note that Tables are weird, and even when creating them programmatically, you run into unexpected situations.
With that said, here are some recommendations:
- Use rows, not columns, to group your cells.
- Create a local master Row to populate each table instance.
- If you reuse Cells between different tables, create a global Cell for each reusable Cell type.
- Resize your cells in your Row master, which will effectively create columns in your table.
The above should give you the most robust Table
component symbol possible.
@Rickvanthof here’s a proposal! I’ll break down the components and also share a sample file. Let me know what you think and also of any tweaks you need!
The key for columns to resize is to separate the text from the background, in that way, overriding one cell makes the entire column grow. So here’s the breakdown of the structure:
- One symbol for the table cell text
- One symbol for the table cell background
One base column symbol
I created the column symbol by placing one pair of the base symbols for each cell. In the exercise I did, I created a 10 row column (header included) which has 10 symbols for text, 10 for background
Creating the full table
I used the column symbol to create the full table. In this case I put 4 columns, but you can add more and hide unnecessary columns in the instances. Here’s how a new fresh instance looks and also after adding overrides:
Being made of symbols, this setup creates a lot of override fields on the inspector, so I recommend overriding directly on canvas, or using the same structure but with Smart Layout groups.
So what do you think? Let me know and we’ll keep tweaking this and find a solution to your use case!
Smart Layout table.sketch (174.9 KB)
Yes, this is it! Separating background from content is a great idea
Thanks for the suggestion. Technically this works, but I prefer being able to build tables using column symbols. In my designs I almost always use either 5-10-15 rows (since those are the most common pagination options) but the number of columns can vary between 2 and ±16.
We’re doing layouts with many many many tables (financial data). This solution helped a LOT, thank you so much!
Hey @fab1An !
Awesome! I’m really glad that you found this useful! Let me know if you run into any issues or have some questions, feedback or need some tweaks!