Home / Function/ DataTableFacetedFilter() — ui Function Reference

DataTableFacetedFilter() — ui Function Reference

Architecture documentation for the DataTableFacetedFilter() function in data-table-faceted-filter.tsx from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  9f5687c3_f8a0_2f9b_dc63_7e26e949948b["DataTableFacetedFilter()"]
  471f9f35_04a7_990e_a2e9_2cfc2aff613c["data-table-faceted-filter.tsx"]
  9f5687c3_f8a0_2f9b_dc63_7e26e949948b -->|defined in| 471f9f35_04a7_990e_a2e9_2cfc2aff613c
  style 9f5687c3_f8a0_2f9b_dc63_7e26e949948b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

apps/v4/app/(app)/examples/tasks/components/data-table-faceted-filter.tsx lines 34–147

export function DataTableFacetedFilter<TData, TValue>({
  column,
  title,
  options,
}: DataTableFacetedFilterProps<TData, TValue>) {
  const facets = column?.getFacetedUniqueValues()
  const selectedValues = new Set(column?.getFilterValue() as string[])

  return (
    <Popover>
      <PopoverTrigger asChild>
        <Button variant="outline" size="sm" className="h-8 border-dashed">
          <PlusCircle />
          {title}
          {selectedValues?.size > 0 && (
            <>
              <Separator orientation="vertical" className="mx-2 h-4" />
              <Badge
                variant="secondary"
                className="rounded-sm px-1 font-normal lg:hidden"
              >
                {selectedValues.size}
              </Badge>
              <div className="hidden gap-1 lg:flex">
                {selectedValues.size > 2 ? (
                  <Badge
                    variant="secondary"
                    className="rounded-sm px-1 font-normal"
                  >
                    {selectedValues.size} selected
                  </Badge>
                ) : (
                  options
                    .filter((option) => selectedValues.has(option.value))
                    .map((option) => (
                      <Badge
                        variant="secondary"
                        key={option.value}
                        className="rounded-sm px-1 font-normal"
                      >
                        {option.label}
                      </Badge>
                    ))
                )}
              </div>
            </>
          )}
        </Button>
      </PopoverTrigger>
      <PopoverContent className="w-[200px] p-0" align="start">
        <Command>
          <CommandInput placeholder={title} />
          <CommandList>
            <CommandEmpty>No results found.</CommandEmpty>
            <CommandGroup>
              {options.map((option) => {
                const isSelected = selectedValues.has(option.value)
                return (
                  <CommandItem
                    key={option.value}
                    onSelect={() => {
                      if (isSelected) {
                        selectedValues.delete(option.value)
                      } else {
                        selectedValues.add(option.value)
                      }
                      const filterValues = Array.from(selectedValues)
                      column?.setFilterValue(
                        filterValues.length ? filterValues : undefined
                      )
                    }}
                  >
                    <div
                      className={cn(
                        "flex size-4 items-center justify-center rounded-[4px] border",
                        isSelected
                          ? "bg-primary border-primary text-primary-foreground"
                          : "border-input [&_svg]:invisible"
                      )}
                    >
                      <Check className="text-primary-foreground size-3.5" />

Subdomains

Frequently Asked Questions

What does DataTableFacetedFilter() do?
DataTableFacetedFilter() is a function in the ui codebase, defined in apps/v4/app/(app)/examples/tasks/components/data-table-faceted-filter.tsx.
Where is DataTableFacetedFilter() defined?
DataTableFacetedFilter() is defined in apps/v4/app/(app)/examples/tasks/components/data-table-faceted-filter.tsx at line 34.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free