np-table Search

Configure a search input via search. It renders at the leftmost of the table header (headerLeft area) and coexists with the headerLeft slot content.

浏览器不支持,请手动复制 search.en.vue

Basic Usage

import type { TableOption } from 'naive-plus'

const option: TableOption = {
  columns: [
    { key: 'name', label: 'Name' },
    { key: 'age', label: 'Age' },
  ],
  search: {
    key: 'keyword',
    placeholder: 'Search name',
  },
  api: {
    fetch: async ({ page, pageSize }, { keyword }) => {
      // keyword is the search input value
      return { items: [], itemCount: 0 }
    },
  },
}

The search value is merged into the second argument of api.fetch under search.key (defaults to keyword), coexisting with filters and tableRef.params. The field is removed when the input is cleared.

The input watches value changes and triggers a search automatically, no Enter key or click needed. Use debounce to control the debounce time (default 300ms) to avoid frequent requests while typing.

const option: TableOption = {
  // ...
  search: {
    debounce: 500,
  },
}

Types

import type { TableSearchOption } from 'naive-plus'

TableSearchOption

PropDescriptionTypeDefault
keyQuery param name passed to api.fetchstringkeyword
placeholderInput placeholderstringPlease enter keyword
widthInput widthstring | number220
clearableWhether the input is clearablebooleantrue
debounceDebounce time (ms); search triggers automatically after typing stopsnumber300
propsOther props passed through to n-inputInputProps-