reactabular-highlight
Highlighting for Reactabular
Last updated 4 years ago by bebraw .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install reactabular-highlight 
SYNC missed versions from official npm registry.

To make it possible to highlight search results per column, there's a specific highlight.cell formatter.

How to Use?

To use it, you'll first you have to annotate your rows using highlight.highlighter. It attaches a structure like this there:

_highlights: {
  demo: [{ startIndex: 0, length: 4 }]
}

Example:

/*
import React from 'react';
import { compose } from 'redux';
import {
  Table, search, Search, highlight
} from 'reactabular';
*/

class HighlightTable extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      query: {},
      columns: [
        {
          property: 'name',
          header: {
            label: 'Name'
          },
          cell: {
            format: highlight.cell
          }
        },
        {
          property: 'age',
          header: {
            label: 'Age'
          },
          cell: {
            format: highlight.cell
          }
        }
      ],
      rows: [
        {
          id: 100,
          name: 'Adam',
          age: 12
        },
        {
          id: 101,
          name: 'Brian',
          age: 7
        },
        {
          id: 102,
          name: 'Jake',
          age: 88
        },
        {
          id: 103,
          name: 'Jill',
          age: 50
        }
      ]
    };
  }
  render() {
    const { rows, columns, query } = this.state;
    const filteredRows = compose(
      highlight.highlighter({ columns, matches: search.matches, query }),
      search.multipleColumns({ columns, query })
    )(rows);

    return (
      <div>
        <div className="search-container">
          <span>Search</span>
          <Search
            query={query}
            columns={columns}
            rows={rows}
            onChange={query => this.setState({ query })}
          />
        </div>
        <Table.Provider columns={columns}>
          <Table.Header />

          <Table.Body rows={filteredRows} rowKey="id" />
        </Table.Provider>
      </div>
    );
  }
}

<HighlightTable />

Current Tags

  • 2.0.5-alpha.331d29a6                                ...           canary (4 years ago)
  • 6.0.0                                ...           latest (4 years ago)

18 Versions

  • 6.0.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.0.5-alpha.331d29a6                                ...           4 years ago
  • 2.0.5-alpha.f20b57cb                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.2.6-alpha.61e29539                                ...           4 years ago
  • 1.2.5                                ...           4 years ago
  • 1.2.3                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.9                                ...           4 years ago
  • 1.0.6                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2017 © taobao.org |