A quick filter lets users search across multiple columns with a single text value. LyteNyte Grid keeps rows where any eligible column matches the search term and hides all others.
Set the quickSearch
value on the grid state to enable quick filtering. LyteNyte Grid will search
across all eligible columns using this value.
By default, every column is included in the search. This can be useful, but in grids with many
numeric columns, it may lead to unwanted matches. To exclude a column, set its quickSearchIgnore
property to true
.
A common pattern is to set quickSearchIgnore
in the base column definition, then selectively
enable quick search for specific columns. In the example below, only the Job
and Education
columns are searchable.
"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", quickSearchIgnore: false },
{ id: "balance", type: "number" },
{ id: "education", quickSearchIgnore: false },
{ id: "marital" },
{ id: "default" },
{ id: "housing" },
{ id: "loan" },
{ id: "contact" },
{ id: "day", type: "number" },
{ id: "month" },
{ id: "duration" },
{ id: "campaign" },
{ id: "pdays" },
{ id: "previous" },
{ id: "poutcome" },
{ id: "y" },
];
export default function FilterQuick() {
const ds = useClientRowDataSource({
data: bankDataSmall,
});
const grid = Grid.useLyteNyte({
gridId: useId(),
rowDataSource: ds,
columns,
columnBase: {
quickSearchIgnore: true,
},
});
const view = grid.view.useValue();
return (
<div style={{ display: "flex", flexDirection: "column" }}>
<div className="flex gap-2 py-2">
<label className="flex gap-2 px-2">
Quick Search
<input
className="rounded px-2 border border-gray-500/20"
placeholder="search..."
value={grid.state.quickSearch.useValue() ?? ""}
onChange={(e) => grid.state.quickSearch.set(e.target.value)}
/>
</label>
</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>
);
}
Use the quickSearchSensitivity
property on the grid to specify case sensitivity for quick search.
Set it to match your application's requirements-case sensitive or case insensitive.