Creating tables with grids

Hello,

I’m trying to set up a table, and the grid layout seems fine for this, but I can’t achieve what I want to do:

The cells content is a component (text + icon like “sort column”)
The cell must grow if the text in the component is larger than the cell
I need a 1px row for my border (can’t we add a bg color on one row or cell individually?)

I thought grid layout could help me but I’m on it for hours, and there is always something off, like the text in the component not “pushing” the cell, or when it worked, the 1px row stays in place despite the “auto” setting of the cell above.

Please help if you have any idea!

Hi @julien. I think I’ve been able to achieve what you’re after:

Table using grid and components.penpot (190.0 KB)

Here the cell is a component, with variant options for header cell (with background colour, bold text, and icon) or default cell:

The cell uses a flex layout so it can fill the height and width of the container. The content is vertically centred and uses justify content space-between to make sure the text stays aligned to the left while the icon will stick to the right side.

To do this, I’ve required a combination of features:

1: Cell text is set to auto-height. This means that when the text exceeds the width of its cell, it drops on to a second line.

2: The cell layout itself is set to fill height and fill width. This ensures the text stays aligned correctly in the grid, regardless of the size of other cells. It also helps the borders stick to the outside of the cell. (Each cell has a 0.5 stroke to make a combined 1px border between cells.) And the background colour to fill the whole cell.

3: To make sure the grid expands and collapses to fit the cell content, the table is one grid layout with the width and height all set to auto. This makes the grid fit the size of the content inside each cell.

Other folks looking into making data tables using grid layout might also find the Penpot team’s Tables plugin helpful:

1 Like

Thank you for your help!

I think that I have a problem because my borders are rectangle objects, and I can’t cheat/hack with the 0,5 border because I don’t want the border on all sides. So I can’t use the space-between in flex.