DataTable Slider Filter
niko-table/data-table-slider-filterFreeComponent
Slider-based filter for numeric range filtering.
Install it
npx shadcn@latest add https://niko-table.com/r/data-table-slider-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 * as React from "react"15import { useDataTable } from "../core/data-table-context"16import {17 TableSliderFilter,18 type TableSliderFilterProps,19} from "../filters/table-slider-filter"20import { useDerivedColumnTitle } from "../hooks/use-derived-column-title"21import { FILTER_VARIANTS } from "../lib/constants"2223type DataTableSliderFilterProps<TData> = Omit<24 TableSliderFilterProps<TData>,25 "column" | "title"26> & {27 /**28 * The accessor key of the column to filter (matches column definition)29 */30 accessorKey: keyof TData & string31 /**32 * Optional title override (if not provided, will use column.meta.label)33 */34 title?: string35}3637/**38 * A slider filter component that automatically connects to the DataTable context39 * and derives the title from column metadata.40 *41 * @example - Auto-detect everything from column metadata and data42 * const columns: DataTableColumnDef[] = [{ accessorKey: "price",..., meta: { label: "Price", unit: "$", range: [0, 1000] } },...]43 * <DataTableSliderFilter accessorKey="price" />44 *45 * @example - Custom range shorthand with unit46 * <DataTableSliderFilter47 * accessorKey="price"48 * range={[0, 1000]}49 * unit="$"50 * />51 *52 * @example - Individual min/max control53 * <DataTableSliderFilter54 * accessorKey="rating"55 * min={1}56 * max={5}57 * step={0.5}58 * />59 *60 * @example - Full manual control with custom title61 * <DataTableSliderFilter62 * accessorKey="distance"63 * title="Distance Range"64 * range={[0, 100]}65 * step={5}66 * unit="km"67 * />68 */6970export function DataTableSliderFilter<TData>({71 accessorKey,72 title,73 ...props74}: DataTableSliderFilterProps<TData>) {75 const { table } = useDataTable<TData>()76 const column = table.getColumn(accessorKey as string)7778 const derivedTitle = useDerivedColumnTitle(column, String(accessorKey), title)7980 // Auto-set variant in column meta if not already set81 // This allows the auto-filterFn to be applied based on variant82 React.useMemo(() => {83 if (!column) return84 const meta = (column.columnDef.meta ||= {})85// … 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 |
