LyteNyte Grid lets you customize header height flexibly. The header can contain three components:
Column group rows appear only when you organize columns into groups. The
floating header row appears only when you set the floatingRowEnabled
property to true
.
Set the column header height with the headerHeight
property. Pass a
number
value representing the height in pixels.
"use client";
import { Grid, useClientRowDataSource } from "@1771technologies/lytenyte-pro";
import "@1771technologies/lytenyte-pro/grid.css";
import type { Column } from "@1771technologies/lytenyte-pro/types";
import { bankDataSmall } from "@1771technologies/sample-data/bank-data-smaller";
import { useId } from "react";
type BankData = (typeof bankDataSmall)[number];
const columns: Column<BankData>[] = [
{ id: "age", type: "number" },
{ id: "job" },
{ id: "balance", type: "number" },
{ id: "education" },
{ id: "marital" },
];
export default function ColumnHeaderHeight() {
const ds = useClientRowDataSource({ data: bankDataSmall });
const grid = Grid.useLyteNyte({
gridId: useId(),
rowDataSource: ds,
columns,
headerHeight: 60,
columnBase: {
widthFlex: 1,
},
});
const view = grid.view.useValue();
return (
<div style={{ display: "flex", flexDirection: "column" }}>
<div
style={{ display: "flex", gap: 8, alignItems: "center" }}
className="py-2"
>
<div>Change Header Height: </div>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.headerHeight.set(30)}
>
Small
</button>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.headerHeight.set(50)}
>
Medium
</button>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.headerHeight.set(80)}
>
Large
</button>
</div>
<div className="lng-grid" style={{ height: 500 }}>
<Grid.Root grid={grid}>
<Grid.Viewport>
<Grid.Header>
{view.header.layout.map((row, i) => {
return (
<Grid.HeaderRow key={i} headerRowIndex={i}>
{row.map((c) => {
if (c.kind === "group") return null;
return (
<Grid.HeaderCell
key={c.id}
cell={c}
className="flex w-full h-full capitalize px-2 items-center"
/>
);
})}
</Grid.HeaderRow>
);
})}
</Grid.Header>
<Grid.RowsContainer>
<Grid.RowsCenter>
{view.rows.center.map((row) => {
if (row.kind === "full-width") return null;
return (
<Grid.Row row={row} key={row.id}>
{row.cells.map((c) => {
return (
<Grid.Cell
key={c.id}
cell={c}
className="text-sm flex items-center px-2 h-full w-full"
/>
);
})}
</Grid.Row>
);
})}
</Grid.RowsCenter>
</Grid.RowsContainer>
</Grid.Viewport>
</Grid.Root>
</div>
</div>
);
}
You can change the column header height after setup:
// Set the header height to 24px
grid.state.headerHeight.set(24);
When using column groups, some columns might not belong to any group or might belong to groups with fewer levels than the deepest group. In such cases, the column header spans multiple group rows, increasing its height based on the rows spanned.
"use client";
import { Grid, useClientRowDataSource } from "@1771technologies/lytenyte-pro";
import "@1771technologies/lytenyte-pro/grid.css";
import type { Column } from "@1771technologies/lytenyte-pro/types";
import { bankDataSmall } from "@1771technologies/sample-data/bank-data-smaller";
import { useId } from "react";
type BankData = (typeof bankDataSmall)[number];
const columns: Column<BankData>[] = [
{ id: "age", type: "number", groupPath: ["One Group"] },
{ id: "job", groupPath: ["One Group", "Second Level"] },
{ id: "balance", type: "number" },
{ id: "education" },
{ id: "marital" },
];
export default function ColumnHeaderHeightSpans() {
const ds = useClientRowDataSource({ data: bankDataSmall });
const grid = Grid.useLyteNyte({
gridId: useId(),
rowDataSource: ds,
columns,
columnBase: {
widthFlex: 1,
},
});
const view = grid.view.useValue();
return (
<div className="lng-grid" style={{ height: 500 }}>
<Grid.Root grid={grid}>
<Grid.Viewport>
<Grid.Header>
{view.header.layout.map((row, i) => {
return (
<Grid.HeaderRow key={i} headerRowIndex={i}>
{row.map((c) => {
if (c.kind === "group") {
return (
<Grid.HeaderGroupCell
key={c.idOccurrence}
cell={c}
className="flex items-center gap-2 px-2"
>
<div>{c.groupPath.at(-1)}</div>
</Grid.HeaderGroupCell>
);
}
return (
<Grid.HeaderCell
key={c.id}
cell={c}
className="flex w-full h-full capitalize px-2 items-center"
/>
);
})}
</Grid.HeaderRow>
);
})}
</Grid.Header>
<Grid.RowsContainer>
<Grid.RowsCenter>
{view.rows.center.map((row) => {
if (row.kind === "full-width") return null;
return (
<Grid.Row row={row} key={row.id}>
{row.cells.map((c) => {
return (
<Grid.Cell
key={c.id}
cell={c}
className="text-sm flex items-center px-2 h-full w-full"
/>
);
})}
</Grid.Row>
);
})}
</Grid.RowsCenter>
</Grid.RowsContainer>
</Grid.Viewport>
</Grid.Root>
</div>
);
}
Use the headerGroupHeight
property to set the height of each column
group header row. Column groups can form multi-level hierarchies.
"use client";
import { Grid, useClientRowDataSource } from "@1771technologies/lytenyte-pro";
import "@1771technologies/lytenyte-pro/grid.css";
import type { Column } from "@1771technologies/lytenyte-pro/types";
import { bankDataSmall } from "@1771technologies/sample-data/bank-data-smaller";
import { useId } from "react";
type BankData = (typeof bankDataSmall)[number];
const columns: Column<BankData>[] = [
{ id: "age", type: "number", groupPath: ["One Group"] },
{ id: "job", groupPath: ["One Group", "Second Level"] },
{ id: "balance", type: "number" },
{ id: "education" },
{ id: "marital" },
];
export default function ColumnHeaderGroupHeight() {
const ds = useClientRowDataSource({ data: bankDataSmall });
const grid = Grid.useLyteNyte({
gridId: useId(),
rowDataSource: ds,
columns,
headerGroupHeight: 20,
columnBase: {
widthFlex: 1,
},
});
const view = grid.view.useValue();
return (
<div style={{ display: "flex", flexDirection: "column" }}>
<div
style={{ display: "flex", gap: 8, alignItems: "center" }}
className="py-2"
>
<div>Change Header Group Height: </div>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.headerGroupHeight.set(20)}
>
Small
</button>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.headerGroupHeight.set(50)}
>
Medium
</button>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.headerGroupHeight.set(80)}
>
Large
</button>
</div>
<div className="lng-grid" style={{ height: 500 }}>
<Grid.Root grid={grid}>
<Grid.Viewport>
<Grid.Header>
{view.header.layout.map((row, i) => {
return (
<Grid.HeaderRow key={i} headerRowIndex={i}>
{row.map((c) => {
if (c.kind === "group") {
return (
<Grid.HeaderGroupCell
key={c.idOccurrence}
cell={c}
className="flex items-center gap-2 px-2"
>
<div>{c.groupPath.at(-1)}</div>
</Grid.HeaderGroupCell>
);
}
return (
<Grid.HeaderCell
key={c.id}
cell={c}
className="flex w-full h-full capitalize px-2 items-center"
/>
);
})}
</Grid.HeaderRow>
);
})}
</Grid.Header>
<Grid.RowsContainer>
<Grid.RowsCenter>
{view.rows.center.map((row) => {
if (row.kind === "full-width") return null;
return (
<Grid.Row row={row} key={row.id}>
{row.cells.map((c) => {
return (
<Grid.Cell
key={c.id}
cell={c}
className="text-sm flex items-center px-2 h-full w-full"
/>
);
})}
</Grid.Row>
);
})}
</Grid.RowsCenter>
</Grid.RowsContainer>
</Grid.Viewport>
</Grid.Root>
</div>
</div>
);
}
You can change the column group header height by updating the
headerGroupHeight
state:
// Set the column group header height to 30px
grid.state.headerGroupHeight.set(30);
The floating row appears as an extra header row under the column header.
It's useful for showing supplementary info or interactive components
like floating filters. Use the floatingRowHeight
property to set its
height.
"use client";
import { Grid, useClientRowDataSource } from "@1771technologies/lytenyte-pro";
import "@1771technologies/lytenyte-pro/grid.css";
import type { Column } from "@1771technologies/lytenyte-pro/types";
import { bankDataSmall } from "@1771technologies/sample-data/bank-data-smaller";
import { useId } from "react";
type BankData = (typeof bankDataSmall)[number];
const columns: Column<BankData>[] = [
{ id: "age", type: "number" },
{ id: "job" },
{ id: "balance", type: "number" },
{ id: "education" },
{ id: "marital" },
];
export default function ColumnHeaderFloatingRowHeight() {
const ds = useClientRowDataSource({ data: bankDataSmall });
const grid = Grid.useLyteNyte({
gridId: useId(),
rowDataSource: ds,
columns,
floatingRowEnabled: true,
floatingRowHeight: 20,
columnBase: {
widthFlex: 1,
},
});
const view = grid.view.useValue();
return (
<div style={{ display: "flex", flexDirection: "column" }}>
<div
style={{ display: "flex", gap: 8, alignItems: "center" }}
className="py-2"
>
<div>Change Floating Row Height: </div>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.floatingRowHeight.set(20)}
>
Small
</button>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.floatingRowHeight.set(50)}
>
Medium
</button>
<button
className="bg-gray-900 text-white border border-gray-600 rounded px-2"
onClick={() => grid.state.floatingRowHeight.set(80)}
>
Large
</button>
</div>
<div className="lng-grid" style={{ height: 500 }}>
<Grid.Root grid={grid}>
<Grid.Viewport>
<Grid.Header>
{view.header.layout.map((row, i) => {
return (
<Grid.HeaderRow key={i} headerRowIndex={i}>
{row.map((c) => {
if (c.kind === "group") return null;
if (c.kind === "floating") {
return (
<Grid.HeaderCell
key={c.id}
cell={c}
className="flex w-full h-full capitalize px-2 items-center"
>
Floating Cell
</Grid.HeaderCell>
);
}
return (
<Grid.HeaderCell
key={c.id}
cell={c}
className="flex w-full h-full capitalize px-2 items-center"
/>
);
})}
</Grid.HeaderRow>
);
})}
</Grid.Header>
<Grid.RowsContainer>
<Grid.RowsCenter>
{view.rows.center.map((row) => {
if (row.kind === "full-width") return null;
return (
<Grid.Row row={row} key={row.id}>
{row.cells.map((c) => {
return (
<Grid.Cell
key={c.id}
cell={c}
className="text-sm flex items-center px-2 h-full w-full"
/>
);
})}
</Grid.Row>
);
})}
</Grid.RowsCenter>
</Grid.RowsContainer>
</Grid.Viewport>
</Grid.Root>
</div>
</div>
);
}
You can also update the floating row height dynamically:
// Set the floating row height to 24px
grid.state.floatingRowHeight.set(24);