CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-tabulator-tables

Interactive table generation JavaScript library with sorting, filtering, editing, formatting, and extensive customization capabilities

Pending
Overview
Eval results
Files

filtering-search.mddocs/

Filtering and Search

Advanced filtering system with multiple filter types, header filters, and search capabilities for precise data visibility control.

Capabilities

Table Filters

Programmatic filtering with support for multiple simultaneous filters and complex filtering logic.

/**
 * Set table filters, replacing any existing filters
 * @param filters - Single filter or array of filter objects
 */
setFilter(filters: FilterParams | FilterParams[]): void;

/**
 * Add new filter to existing filters
 * @param field - Field name to filter on
 * @param type - Filter comparison type
 * @param value - Value to filter against
 * @param params - Additional filter parameters
 */
addFilter(field: string, type: FilterType, value: any, params?: any): void;

/**
 * Get all currently active filters
 * @param all - Include inactive filters if true
 * @returns Array of active filter objects
 */
getFilters(all?: boolean): FilterParams[];

/**
 * Remove specific filter
 * @param field - Field name of filter to remove
 * @param type - Filter type to remove
 * @param value - Filter value to remove
 */
removeFilter(field: string, type: FilterType, value: any): void;

/**
 * Clear filters from table
 * @param all - If true, clear header filters too
 */
clearFilter(all?: boolean): void;

Usage Examples:

// Single filter
table.setFilter("department", "=", "Engineering");

// Multiple filters
table.setFilter([
  { field: "age", type: ">=", value: 18 },
  { field: "status", type: "=", value: "active" },
  { field: "name", type: "like", value: "John" }
]);

// Add filter to existing ones
table.addFilter("salary", ">", 50000);

// Complex filter with parameters
table.addFilter("date", ">=", "2023-01-01", { format: "YYYY-MM-DD" });

// Remove specific filter
table.removeFilter("age", ">=", 18);

// Clear all filters
table.clearFilter(true); // Including header filters

Header Filters

Interactive filtering controls built into column headers for user-driven filtering.

/**
 * Set value of specific header filter
 * @param field - Column field name
 * @param value - Value to set in header filter
 */
setHeaderFilterValue(field: string, value: any): void;

/**
 * Get current value of header filter
 * @param field - Column field name
 * @returns Current header filter value
 */
getHeaderFilterValue(field: string): any;

/**
 * Clear all header filter values
 */
clearHeaderFilter(): void;

Data Search

Search functionality for finding specific data within the table.

/**
 * Search table data and return matching data objects
 * @param field - Field name to search in
 * @param type - Search comparison type
 * @param value - Value to search for
 * @returns Array of matching data objects
 */
searchData(field: string, type: FilterType, value: any): any[];

/**
 * Search table and return matching row components
 * @param field - Field name to search in
 * @param type - Search comparison type  
 * @param value - Value to search for
 * @returns Array of matching RowComponents
 */
searchRows(field: string, type: FilterType, value: any): RowComponent[];

Usage Examples:

// Header filter manipulation
table.setHeaderFilterValue("name", "Alice");
const currentFilter = table.getHeaderFilterValue("department");
table.clearHeaderFilter();

// Data search
const matches = table.searchData("email", "like", "@company.com");
const matchingRows = table.searchRows("status", "=", "pending");

// Process search results
matchingRows.forEach(row => {
  row.getElement().style.backgroundColor = "yellow";
});

Filter Types and Parameters

Standard Filter Types

type FilterType = 
  | "=" | "!=" | "like" | "not like" 
  | "<" | "<=" | ">" | ">="
  | "in" | "not in"
  | "regex" | "starts" | "ends"
  | "keywords";

interface FilterParams {
  /** Field name to filter */
  field: string;
  /** Filter comparison type */
  type: FilterType;
  /** Value to filter against */
  value: any;
  /** Additional filter parameters */
  params?: FilterParamsConfig;
}

interface FilterParamsConfig {
  /** Separator for 'in' filters */
  separator?: string;
  /** Case sensitivity for string filters */
  matchAll?: boolean;
  /** Custom filter function */
  filterFunc?: Function;
}

Custom Filter Functions

interface CustomFilterConfig {
  /** Custom filter logic */
  filterFunc: (headerValue: any, rowValue: any, rowData: any, filterParams: any) => boolean;
  /** Filter parameters */
  filterParams?: any;
}

Usage Examples:

// Standard filter types
table.setFilter([
  { field: "name", type: "like", value: "john" },
  { field: "age", type: ">=", value: 21 },
  { field: "department", type: "in", value: "sales,marketing", params: { separator: "," } },
  { field: "email", type: "regex", value: ".*@company\\.com$" },
  { field: "title", type: "starts", value: "Senior" }
]);

// Custom filter function
table.setFilter([{
  field: "score",
  type: "=",
  value: null,
  params: {
    filterFunc: function(headerValue, rowValue, rowData, filterParams) {
      return rowValue >= 80 && rowData.attempts < 3;
    }
  }
}]);

Header Filter Configuration

Header Filter Types

Header filters can be configured per column to provide interactive filtering controls.

interface HeaderFilterOptions {
  /** Filter input type */
  headerFilter?: "input" | "number" | "select" | "tickCross" | "date" | "dateTime" | Function | boolean;
  /** Filter parameters */
  headerFilterParams?: {
    /** Placeholder text */
    placeholder?: string;
    /** Options for select filters */
    values?: any[] | { [key: string]: string };
    /** Multiple selection */
    multiselect?: boolean;
    /** Allow empty option */
    clearable?: boolean;
    /** Tristate for tickCross */
    tristate?: boolean;
  };
  /** Filter comparison function */
  headerFilterFunc?: FilterType | Function;
  /** Parameters for filter function */
  headerFilterFuncParams?: any;
  /** Enable live filtering */
  headerFilterLiveFilter?: boolean;
  /** Live filter delay (ms) */
  headerFilterLiveFilterDelay?: number;
  /** Empty value check */
  headerFilterEmptyCheck?: (value: any) => boolean;
}

Usage Examples:

// Column definitions with header filters
const columnsWithFilters = [
  {
    title: "Name",
    field: "name", 
    headerFilter: "input",
    headerFilterParams: { placeholder: "Search names..." },
    headerFilterFunc: "like"
  },
  {
    title: "Department",
    field: "department",
    headerFilter: "select",
    headerFilterParams: {
      values: {
        "": "All Departments",
        "engineering": "Engineering", 
        "sales": "Sales",
        "marketing": "Marketing"
      },
      clearable: true
    }
  },
  {
    title: "Active",
    field: "active",
    headerFilter: "tickCross",
    headerFilterParams: { tristate: true },
    formatter: "tickCross"
  },
  {
    title: "Salary",
    field: "salary",
    headerFilter: "number",
    headerFilterParams: { placeholder: "Min salary..." },
    headerFilterFunc: ">="
  },
  {
    title: "Hire Date",
    field: "hireDate",
    headerFilter: "date",
    headerFilterParams: { format: "YYYY-MM-DD" },
    headerFilterFunc: ">="
  }
];

table.setColumns(columnsWithFilters);

Advanced Filtering Patterns

Conditional Filtering

// Complex multi-condition filters
table.setFilter([
  [
    { field: "age", type: ">=", value: 18 },
    { field: "age", type: "<=", value: 65 }
  ],
  { field: "status", type: "=", value: "active" }
]);

// Custom filter with complex logic
table.addFilter("custom", "=", null, {
  filterFunc: function(headerValue, rowValue, rowData, filterParams) {
    const experience = new Date().getFullYear() - new Date(rowData.startDate).getFullYear();
    return experience >= 5 && rowData.certifications.length > 0;
  }
});

Filter Events and Callbacks

// Listen for filter changes
table.on("dataFiltered", function(filters, rows) {
  console.log(`${rows.length} rows visible after filtering`);
  console.log("Active filters:", filters);
});

// Pre-filter data processing
table.on("dataFiltering", function(filters) {
  console.log("About to apply filters:", filters);
});

Performance Optimization

// Efficient filtering for large datasets
const efficientTable = new Tabulator("#large-table", {
  data: largeDataset,
  filterMode: "local", // or "remote" for server-side
  headerFilterLiveFilterDelay: 600, // Debounce rapid typing
  pagination: true, // Reduce DOM elements
  paginationSize: 100,
  virtualDom: true // Virtual scrolling
});

Install with Tessl CLI

npx tessl i tessl/npm-tabulator-tables

docs

cell-editing.md

clipboard.md

column-management.md

data-management.md

data-sorting.md

data-trees.md

event-system.md

filtering-search.md

history-undo.md

import-export.md

index.md

pagination.md

range-selection.md

row-grouping.md

table-construction.md

validation.md

tile.json