DataTable Inline Filter
niko-table/data-table-inline-filterFreeComponent
Inline filter toolbar that displays active filters as editable chips.
Install it
npx shadcn@latest add https://niko-table.com/r/data-table-inline-filter.jsonSource
1"use client"23/**4 * niko-table — created by Semir N. (Semkoo, https://github.com/Semkoo) with AI assistance.5 *6 * Before reporting anything: please check the changelog first.7 * - In-repo: ./CHANGELOG.md8 * - Docs site: https://niko-table.com/changelog9 *10 * Found a bug or have a fix? Open an issue or PR on GitHub so other11 * users (and future LLMs reading this code) benefit:12 * https://github.com/Semkoo/niko-table-registry13 */14import React from "react"15import { useDataTable } from "../core/data-table-context"16import {17 TableInline,18 type TableInlineProps,19} from "../filters/table-inline-filter"20import { useGeneratedOptions } from "../hooks/use-generated-options"21import { FILTER_VARIANTS } from "../lib/constants"22import type { Option } from "../types"2324type BaseInlineProps<TData> = Omit<TableInlineProps<TData>, "table">2526interface AutoOptionProps {27 autoOptions?: boolean28 showCounts?: boolean29 dynamicCounts?: boolean30 /**31 * If true, only generate options from filtered rows. If false, generate from all rows.32 * This controls which rows are used to generate the option list itself.33 * Note: This is separate from dynamicCounts which controls count calculation.34 * @default true35 */36 limitToFilteredRows?: boolean37 includeColumns?: string[]38 excludeColumns?: string[]39 limitPerColumn?: number40 mergeStrategy?: "preserve" | "augment" | "replace"41}4243type DataTableInlineFilterProps<TData> = BaseInlineProps<TData> &44 AutoOptionProps4546export function DataTableInlineFilter<TData>({47 autoOptions = true,48 showCounts = true,49 dynamicCounts = true,50 limitToFilteredRows = true,51 includeColumns,52 excludeColumns,53 limitPerColumn,54 mergeStrategy = "preserve",55 ...props56}: DataTableInlineFilterProps<TData>) {57 const { table } = useDataTable<TData>()5859 const generatedOptions = useGeneratedOptions(table, {60 showCounts,61 dynamicCounts,62 limitToFilteredRows,63 includeColumns,64 excludeColumns,65 limitPerColumn,66 mergeStrategy,67 })6869 /**70 * BUG: stale counts on filter changes — see `data-table-filter-menu.tsx`71 * for full doc. We capture pristine caller options in a ref and rebuild72 * `meta.options` from that source on every augment so counts refresh73 * (and zeroes get filled in for the count-0 hide rule).74 */75 React.useMemo(() => {76 if (!autoOptions) return null77 table.getAllColumns().forEach(column => {78 const meta = (column.columnDef.meta ||= {})79// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from niko-table
All 31 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| DataTable Asidedata-table-aside | niko-table | Components | Free | 1 dep | |
| DataTable Clear Filterdata-table-clear-filter | niko-table | Components | Free | 1 dep · 2 files | |
| DataTable Column Auto-fitdata-table-column-auto-fit | niko-table | Components | Free | no deps · 2 files | |
| DataTable Column Date Filterdata-table-column-date-filter | niko-table | Components | Free | 2 deps · 2 files | |
| DataTable Column DnDdata-table-column-dnd | niko-table | Components | Free | 4 deps · 3 files | |
| DataTable Column Faceted Filterdata-table-column-faceted-filter | niko-table | Components | Free | 1 dep · 3 files | |
| DataTable Column Hidedata-table-column-hide | niko-table | Components | Free | 1 dep · 2 files | |
| DataTable Column Pindata-table-column-pin | niko-table | Components | Free | 1 dep · 2 files |
