---
title: Filter and Search Matrix Rows
product: Form Library
description: Search and filter rows in Dynamic and Multi-Select Matrices with the SurveyJS Filter control. Try text search, conditions, and saved filters in a JavaScript demo.
framework: jQuery
source: https://surveyjs.io/form-library/examples/filtering-in-matrices/jquery
index: https://surveyjs.io/form-library/examples/overview.md
---

# Filter and Search Matrix Rows (jQuery)

A Filter control narrows down the rows shown in a [Dynamic Matrix](/form-library/documentation/api-reference/dynamic-matrix-table-question-model) or [Multi-Select Matrix](/form-library/documentation/api-reference/matrix-table-with-dropdown-list). Users can search across fields, apply quick filters, and save and reuse filter presets. The **All Filters** dialog allows them to access the full list of configured fields and manage the presets.

## Add and Bind the Filter Control

Add an element with `type` set to `"filter"` and a unique `name` to your survey JSON. To bind it to a matrix, set [`targetQuestion`](/form-library/documentation/api-reference/questionfiltermodel#targetQuestion) to the matrix's `name`. With this configuration, the matrix updates its visible rows automatically as users search, set conditions, or select a filter preset.

The following example shows how to bind the Filter control to a Dynamic Matrix:

```json
{
  "elements": [
    {
      "type": "filter",
      "name": "dynamicProductFilter",
      "title": "Filter Products",
      "targetQuestion": "dynamicProducts"
    },
    {
      "type": "matrixdynamic",
      "name": "dynamicProducts",
      "columns": [
        { "name": "product", "title": "Product", "cellType": "text" },
        { "name": "price", "title": "Price ($)", "cellType": "text", "inputType": "number" }
      ]
    }
  ]
}
```

## Configure Filter Fields

By default, filter fields are generated based on the matrix's visible columns. Each field inherits the column's name, title, value type, and choices, and the Filter control infers which operators are available. To customize the available fields, define the [`fields`](/form-library/documentation/api-reference/questionfiltermodel#fields) array. Each object in this array can include the following properties:

- [`name`](/form-library/documentation/api-reference/filterfield#name)\
Uniquely identifies the field and binds it to a matrix column. Set it to the column's `name` or `valueName`.

- [`title`](/form-library/documentation/api-reference/filterfield#title)\
Sets the localizable label users see for the field.

- [`operators`](/form-library/documentation/api-reference/filterfield#operators)\
Limits the available filter operators. See [Supported Operators](/form-library/documentation/design-survey/conditional-logic#supported-operators).

- [`showInQuickFilters`](/form-library/documentation/api-reference/filterfield#showInQuickFilters)\
Specifies whether this field is available in quick filters. If you set this property to `false`, the field will be available in **All Filters** only.

The following code example defines two filter fields, `product` and `price`. `product` is hidden from quick filters; `price` contains a limited set of filter operators.

```json
{
  "elements": [
    {
      "type": "filter",
      "name": "dynamicProductFilter",
      "title": "Filter Products",
      "targetQuestion": "dynamicProducts",
      "fields": [
        { "name": "product", "showInQuickFilters": false },
        { "name": "price", "operators": ["equal", "less", "greater"] }
      ]
    },
    {
      // ...
    }
  ]
}
```

## Configure Search

The search bar is enabled by default and searches all available filter fields, including fields hidden from quick filters. Use the [`searchFields`](/form-library/documentation/api-reference/questionfiltermodel#searchFields) array to limit the search to specific fields. Make sure those fields are included in the `fields` array if you define it.

The search bar placeholder lists the searchable fields by default. Set the localizable [`searchPlaceholder`](/form-library/documentation/api-reference/questionfiltermodel#searchPlaceholder) property to customize the text.

The example below limits search to the `product` field and displays a custom placeholder:

```json
{
  "elements": [
    {
      "type": "filter",
      "name": "dynamicProductFilter",
      "title": "Filter Products",
      "targetQuestion": "dynamicProducts",
      "fields": [
        { "name": "product", "showInQuickFilters": false },
        { "name": "price", "operators": ["equal", "less", "greater"] }
      ],
      "searchFields": ["product"],
      "searchPlaceholder": "Search by product name"
    },
    {
      // ...
    }
  ]
}
```

If you want to disable search, set the [`showSearchBar`](/form-library/documentation/api-reference/questionfiltermodel#showSearchBar) property to `false`.

## Configure Filter Presets

Filter presets let users reapply saved conditions. To define presets, use the [`presets`](/form-library/documentation/api-reference/questionfiltermodel#presets) array. Each object in this array can include the following properties:

- [`name`](/form-library/documentation/api-reference/filterpreset#name)\
Uniquely identifies the preset within the Filter control.

- [`title`](/form-library/documentation/api-reference/filterpreset#title)\
Sets the localizable label users see for the preset. The label defaults to the preset's `name`.

- [`expression`](/form-library/documentation/api-reference/filterpreset#expression)\
Determines which rows match the preset. See [Expressions](/form-library/documentation/design-survey/conditional-logic#expressions)

- [`allowEdit`](/form-library/documentation/api-reference/filterpreset#allowEdit)\
Specifies whether users can edit this preset.

- [`allowDelete`](/form-library/documentation/api-reference/filterpreset#allowDelete)\
Specifies whether users can remove this preset.

To apply a preset at startup, assign the preset's `name` set the [`defaultPreset`](/form-library/documentation/api-reference/questionfiltermodel#defaultPreset) property. The example below applies **Under $50** when the matrix first loads:

```json
{
  "elements": [
    {
      "type": "filter",
      "name": "dynamicProductFilter",
      "title": "Filter Products",
      "targetQuestion": "dynamicProducts",
      "presets": [
        { "name": "under50", "title": "Under $50", "expression": "{price} < 50" }
      ],
      "defaultPreset": "under50"
    },
    {
      // ...
    }
  ]
}
```

Enable the [`allowAddPresets`](/form-library/documentation/api-reference/questionfiltermodel#allowAddPresets) property to let users save the current conditions as a filter preset. Users can edit and delete the presets they create without restrictions. If you also want users to edit or delete survey-defined presets, enable the [`allowEditPresets`](/form-library/documentation/api-reference/questionfiltermodel#allowEditPresets) and [`allowDeletePresets`](/form-library/documentation/api-reference/questionfiltermodel#allowDeletePresets) properties. This demo allows users to create custom presets and prevents them from editing or deleting presets defined in the survey.

## See Also

[Demo: Filtering in Dynamic Panel](/form-library/examples/filtering-in-dynamic-panel/ (linkStyle))

## Files

### `public/index.html`

```html
<link href="https://fonts.googleapis.com/css?family=Open%20Sans:400,600&display=swap" rel="stylesheet">
<div id="surveyElement" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0; min-height: 100%; height:100%"></div>
```

### `src/index.css`

```css
/* You can add your custom CSS here. */
```

### `src/index.js`

```js
import $ from "jquery";
import { Model } from "survey-core";
import "survey-js-ui";
import "survey-core/survey-core.min.css";
import "./index.css";
import { json } from "./json";

const survey = new Model(json);
survey.onComplete.add((sender, options) => {
    console.log(JSON.stringify(sender.data, null, 3));
});
const products = [
  { sku: "P101", product: "Desk lamp", category: "Lighting", price: 29, status: "In stock" },
  { sku: "P102", product: "Floor lamp", category: "Lighting", price: 79, status: "Low stock" },
  { sku: "P103", product: "Compact keyboard", category: "Accessories", price: 45, status: "In stock" },
  { sku: "P104", product: "Wireless mouse", category: "Accessories", price: 24, status: "Low stock" },
  { sku: "P105", product: "27-inch monitor", category: "Displays", price: 229, status: "In stock" },
  { sku: "P106", product: "Portable monitor", category: "Displays", price: 149, status: "Backordered" },
  { sku: "P107", product: "USB-C hub", category: "Accessories", price: 39, status: "Backordered" },
  { sku: "P108", product: "Monitor light bar", category: "Lighting", price: 49, status: "In stock" }
];

survey.getQuestionByName("fixedProducts").rows = products.map(({ sku }) => sku);
survey.data = {
  dynamicProducts: products,
  fixedProducts: Object.fromEntries(products.map(product => [product.sku, { ...product }]))
};

survey.onGetQuestionTitleActions.add((_, options) => {
  const questionName = options.question.name;
  if (questionName !== "dynamicProducts" && questionName !== "fixedProducts") return;

  const isDynamic = questionName === "dynamicProducts";
  options.actions.push({
    id: "switch-matrix-type",
    title: isDynamic ? "Switch to Multi-Select Matrix" : "Switch to Dynamic Matrix",
    action: () => {
      survey.currentPageNo = isDynamic ? 1 : 0;
    }
  });
});

$("#surveyElement").Survey({ model: survey });
```

### `src/json.js`

```js
export const json = {
  "showNavigationButtons": false,
  "pages": [
    {
      "name": "dynamic-matrix",
      "elements": [
        {
          "type": "filter",
          "name": "dynamicProductFilter",
          "title": "Filter Products",
          "targetQuestion": "dynamicProducts",
          "searchFields": [
            "product",
            "sku"
          ],
          "allowAddPresets": true,
          "fields": [
            {
              "name": "sku",
              "showInQuickFilters": false
            },
            {
              "name": "product",
              "showInQuickFilters": false
            },
            {
              "name": "category"
            },
            {
              "name": "status"
            },
            {
              "name": "price",
              "operators": [
                "equal",
                "less",
                "greater"
              ]
            }
          ],
          "presets": [
            {
              "name": "inStock",
              "title": "In stock",
              "expression": "{status} = 'In stock'"
            },
            {
              "name": "under50",
              "title": "Under $50",
              "expression": "{price} < 50"
            }
          ]
        },
        {
          "type": "matrixdynamic",
          "name": "dynamicProducts",
          "title": "Product Inventory (Dynamic Matrix)",
          "columns": [
            {
              "name": "sku",
              "title": "SKU",
              "width": "80px",
              "minWidth": "80px",
              "cellType": "text"
            },
            {
              "name": "product",
              "title": "Product",
              "cellType": "text"
            },
            {
              "name": "category",
              "title": "Category",
              "choices": [
                "Accessories",
                "Lighting",
                "Displays"
              ]
            },
            {
              "name": "price",
              "title": "Price ($)",
              "width": "90px",
              "minWidth": "90px",
              "cellType": "text",
              "inputType": "number"
            },
            {
              "name": "status",
              "title": "Stock status",
              "choices": [
                "In stock",
                "Low stock",
                "Backordered"
              ]
            }
          ],
          "addRowText": "Add Product"
        }
      ]
    },
    {
      "name": "multi-select-matrix",
      "elements": [
        {
          "type": "filter",
          "name": "fixedProductFilter",
          "title": "Filter Products",
          "targetQuestion": "fixedProducts",
          "searchFields": [
            "product",
            "sku"
          ],
          "allowAddPresets": true,
          "fields": [
            {
              "name": "sku",
              "title": "SKU",
              "showInQuickFilters": false
            },
            {
              "name": "product",
              "showInQuickFilters": false
            },
            {
              "name": "category"
            },
            {
              "name": "status"
            },
            {
              "name": "price",
              "operators": [
                "equal",
                "less",
                "greater"
              ]
            }
          ],
          "presets": [
            {
              "name": "inStock",
              "title": "In stock",
              "expression": "{status} = 'In stock'"
            },
            {
              "name": "under50",
              "title": "Under $50",
              "expression": "{price} < 50"
            }
          ]
        },
        {
          "type": "matrixdropdown",
          "name": "fixedProducts",
          "title": "Product Inventory (Multi-Select Matrix)",
          "rowTitleWidth": "80px",
          "columns": [
            {
              "name": "product",
              "title": "Product",
              "cellType": "text"
            },
            {
              "name": "category",
              "title": "Category",
              "choices": [
                "Accessories",
                "Lighting",
                "Displays"
              ]
            },
            {
              "name": "price",
              "title": "Price ($)",
              "width": "90px",
              "minWidth": "90px",
              "cellType": "text",
              "inputType": "number"
            },
            {
              "name": "status",
              "title": "Stock status",
              "choices": [
                "In stock",
                "Low stock",
                "Backordered"
              ]
            }
          ]
        }
      ]
    }
  ]
}
;
```

### `src/theme.js`

```js
export const themeJson = {};
```

### `package.json`

```json
{
  "dependencies": {
    "jquery": "latest",
    "survey-core": "latest",
    "survey-js-ui": "latest"
  }
}
```

## Other Frameworks

- [Angular](https://surveyjs.io/form-library/examples/filtering-in-matrices/angular.md)
- [React](https://surveyjs.io/form-library/examples/filtering-in-matrices/reactjs.md)
- [Vue 3](https://surveyjs.io/form-library/examples/filtering-in-matrices/vue3js.md)
- [Vanilla JS](https://surveyjs.io/form-library/examples/filtering-in-matrices/vanillajs.md)
