Filtering

Column Filters

LyteNyte Grid lets you filter data by applying filters to individual columns. Use the filterModel property on the grid to control which columns have filters applied.

The column filter model consists of key/value pairs, where each key is a column id and each value is the filter to apply. This section covers simple filters, available in both Core and PRO editions of LyteNyte Grid. The PRO edition also supports:

Applying Column Filters

Apply a column filter by setting the filter value for a column in the filterModel property of grid state. LyteNyte Grid offers several types of simple filters to handle diverse filtering requirements. An example filter model may look like the code below:

const filterModel = {
  job: {
    simple: {
      columnId: "job",
      kind: "text",
      operator: "contains",
      value: "tech",
    },
  },
};

Text Filter

Use text filters to filter columns with textual values. These filters support common operations like begins_with and contains. In the example below we filter for rows that have a job field value that contains "tech".

Text Filter

Number Filter

Apply number filters to columns containing numeric values. Like text filters, number filters support common operations such as less_than or equal. In the example below, we filter out all the rows that have an age less than 30.

Number Filter

Date Filter

Use date filters for columns containing date values. Beyond common filter operators, date filters allow filtering to specific time periods, such as the first quarter of the current year.

In the example below we filter the rows to only keep those rows that are in Q2 of the year or don't have a date value.

Date Filter

Combined Filter

When you need to filter a column using two conditions, use a combined filter. This lets you create an and/or filter for a given column. The combined filter takes left and right operands for filtering, with an operator that can be either and or or.

Combined Filter

Function Filter

While the filters above cover most use cases, sometimes you need custom control over filtering behavior. Function filters serve this purpose. Write an arbitrary function predicate that returns true for rows you want to keep (not filter out). For example we can filter out all the rows that have an odd age value.

Function Filter

Managing Filters

The filterModel property serves as the source of truth for simple filters in LyteNyte Grid. Perform common operations by setting values on the grid state. For example, to delete a filter:

const model = grid.state.filterModel;
 
// Clear all filters
model.set({});
 
// Delete a specific filter
const columnId = "<id-of-column-to-remove>";
model.set((prev) => {
  const next = { ...prev };
  delete next[columnId];
 
  return next;
});