LyteNyte Grid logo for light mode. Links back to the documentation home page.
Rows

Row Height

LyteNyte Grid allows developers to control row height. Rows can have a fixed height, vary in height per row, or expand to fill the available viewport space.

The rowHeight property on the grid state controls how LyteNyte Grid calculates each row’s height in pixels. This property accepts three possible values:

  • Numbers: Sets all rows to a fixed height in pixels.
  • Functions: Returns the height in pixels for each row. Use this option to create variable row heights.
  • Fill String: A string of the form fill:<number>. For example, fill:24 instructs LyteNyte Grid to distribute the available viewport space across all rows, while enforcing a minimum height of 24px per row.

Number Row Heights

Set rowHeight to a number to give all rows a uniform height. The numeric value represents the row height in pixels. The demo below shows fixed row heights in action.

Fixed Row Height

//!
Fork code on stack blitzFork code on code sandbox

Variable Row Height

LyteNyte Grid supports variable row heights through a function callback. This function must return a number representing the row height in pixels, and the returned value may differ per row.

LyteNyte Grid calls this function for every row during layout, so performance is critical. Keep the implementation simple and avoid expensive calculations inside the callback.

The demo below illustrates variable row heights in practice.

Variable Row Height

//!
Fork code on stack blitzFork code on code sandbox

In this example, the row height cycles through a predefined set of values. While this demo uses a simple pattern, your own logic can be as complex as needed, as long as it remains performant.

const rowHeight = (i: number) => [30, 50, 80, 120][i % 4];

Fill Row Height

Use the fill row height syntax "fill:<n>" to make rows expand and fill the available viewport space, where n is the minimum row height in pixels.

LyteNyte Grid assigns each row its minimum height, calculates the remaining available space, and then distributes that space evenly across all rows. This approach works well when the grid displays only a small number of rows and you want them to occupy the full viewport height.

Fill Row Height

//!
Fork code on stack blitzFork code on code sandbox

Info

When using fill row heights, if the combined minimum height of all rows exceeds the viewport height, the grid cannot distribute additional space. In this case, each row renders at exactly its minimum height, behaving the same as fixed-height rows.

Next Steps