# reactabular-search

> Search for Reactabular

Latest version **6.1.1** (published 2016-10-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install reactabular-search
pnpm add reactabular-search
yarn add reactabular-search
bun add reactabular-search
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.1.1 |
| Published | 2016-10-27 |
| First published | 2016-07-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 913 |
| Author | Juho Vepsalainen |
| Maintainers | bebraw |
| Keywords | react, reactjs, table, tables, reactabular |

## Links

- npm: https://www.npmjs.com/package/reactabular-search
- Repository: https://github.com/reactabular/reactabular
- Homepage: http://reactabular.js.org/
- Issues: https://github.com/reactabular/reactabular/issues
- npm.io page: https://npm.io/package/reactabular-search

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 6.1.1 (latest) — 2016-10-27
- 2.0.5-alpha.331d29a6 (canary) — 2016-08-31
- 6.0.0 — 2016-10-14
- 4.2.0 — 2016-09-23
- 3.0.0 — 2016-09-01
- 2.0.5-alpha.f20b57cb — 2016-08-31
- 2.0.1 — 2016-08-16
- 2.0.0 — 2016-08-16
- 1.2.6-alpha.61e29539 — 2016-08-15
- 1.2.3 — 2016-08-08
- 1.1.0 — 2016-08-03
- 1.0.9 — 2016-07-29
- 1.0.5 — 2016-07-27
- 1.0.4 — 2016-07-26
- 1.0.2 — 2016-07-26
- … 2 more at https://npm.io/package/reactabular-search/versions

## README

Reactabular comes with search helpers. It consists of search algorithms that can be applied to the rows. Just like with sorting, you have to apply it to the rows just before rendering. A column is considered searchable in case it has a unique `property` defined.

## How to Use?

The general workflow goes as follows:

1. Set up a `Search` control that outputs a query in `{<column>: <query>}` format. If `<column>` is `all`, then the search will work against all columns. Otherwise it will respect the exact columns set. You'll most likely want to use either `reactabular-search-field` or `reactabular-search-columns` (or both) for this purpose or provide an implementation of your own.
2. Before rendering the rows, perform `search.multipleColumns({ columns, query })(rows)`. This will filter the rows based on the passed `rows`, `columns` definition, and `query`. A lazy way to do this is to filter at `render()` although you can do it elsewhere too to optimize rendering.
3. Pass the filtered rows to `Table`.

## API

The Search API consists of three parts. Out of these `search.multipleColumns` and `search.matches` are the most useful ones for normal usage. If the default search strategies aren't enough, it's possible to implement more as long as you follow the same interface.

### Search

**`search.multipleColumns({ castingStrategy: <castingStrategy>, columns: [<object>], query: {<column>: <query>}, strategy: <strategy>, transform: <transform> })([<rows to query>]) => [<filtered rows>]`**

This is the highest level search function available. It expects `rows` and `columns` in the same format the `Table` uses. `query` object describes column specific search queries.

It uses `infix` strategy underneath although it is possible to change it. By default it matches in a case **insensitive** manner. If you want case sensitive behavior, pass `a => a`(identity function) as `transform`.

It will cast everything but arrays to a string by default. If you want a custom casting behavior, pass a custom function to `castingStrategy`.

**`search.singleColumn({ castingStrategy: <castingStrategy>, columns: [<object>], searchColumn: <string>, query: <string>, strategy: <strategy>, transform: <transform> })([<rows to query>]) => [<filtered rows>]`**

This is a more specialized version of `search.multipleColumns`. You can use it to search a specific column through `searchColumn` and `query`.

### Matchers

**`search._columnMatches({ query: <string>, castingStrategy: <castingStrategy>, column: <object>, row: <object>, strategy: <strategy>, transform: <transform> }) => <boolean>`**

This is a function that can be used to figure out all column specific matches. It is meant only for **internal usage** of the library.

When dealing with strings:

**`search.matches({ value: <string>, query: <string>, strategy: <strategy>, transform: <transform> }) => [{ startIndex: <number>, length: <number> }]`**

Returns an array with the matches.

When dealing with arrays:

**`search.matches({ value: <string>, query: [<string|[...]>], strategy: <strategy>, transform: <transform> }) => [[{ startIndex: <number>, length: <number> }], ...]`**

Returns a sparse array with the same shape as the original query. If there was a match for an item, it will have the same shape as the string version above, otherwise the array will have a hole in that location.

This function returns matches against the given value and query. This is particularly useful with highlighting.

### Strategies

**`search.strategies.infix(queryTerm: <string>) => { evaluate(searchText: <string>) => <string>, matches(searchText) => [{ startIndex: <number>, length: <number> }]`**

Search uses `infix` strategy by default. This means it will match even if the result is in the middle of a `searchText`.

The strategies operate in two passes - evaluation and matching. The evaluation pass allows us to implement perform fast boolean check on whether or not a search will match. Matching gives exact results.

**`search.strategies.prefix(queryTerm: <string>) => { evaluate(searchText: <string>) => <string>, matches(searchText) => [{ startIndex: <number>, length: <number> }]`**

`prefix` strategy matches from the start.

---
_Source: https://npm.io/package/reactabular-search · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
