最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Use custom filter input component with Griddle - Stack Overflow

programmeradmin4浏览0评论

I'm using griddle a react ponent to create a table.

Griddle supports a extra attribute to show a filter input element, which manipulates the table.

Is there a way to use your own independent form / input with griddle. So that when the third-party input is submitted I can trigger some function within griddle to update table?

I've looked at the docs and put an issue here on the project. I have no idea how to acplish this.

I'm using griddle a react ponent to create a table.

Griddle supports a extra attribute to show a filter input element, which manipulates the table.

Is there a way to use your own independent form / input with griddle. So that when the third-party input is submitted I can trigger some function within griddle to update table?

I've looked at the docs and put an issue here on the project. I have no idea how to acplish this.

Share Improve this question edited Jun 25, 2016 at 23:07 Laurel 6,19114 gold badges34 silver badges59 bronze badges asked Sep 17, 2015 at 16:59 ThomasReggiThomasReggi 59.8k97 gold badges259 silver badges459 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

As exemplified in this demo you can specify a custom filter and custom ponent:

var _ = require('underscore'),
    squish = require('object-squish');

var customFilterFunction = function(items, query) {
  return _.filter(items, (item) => {
    var flat = squish(item);

    for (var key in flat) {
      if (String(flat[key]).toLowerCase().indexOf(query.toLowerCase()) >= 0)
        return true;
    }

    return false;
  });
};

var customFilterComponent = React.createClass({
  getInitialState() {
    return {
      "query": ""
    };
  },
  searchChange(event) {
    this.setState({
      query: event.target.value
    });
    // this line is important
    this.props.changeFilter(this.state.query);
  },
  render() {
    return (
      <div className="filter-container">
        <input type="text"
               name="search"
               placeholder="Search..."
               onChange={this.searchChange} />
      </div>
    );
  }
});

Then you can initialize your Griddle table like this:

React.render(
  <Griddle results={fakeData} showFilter={true}
    useCustomFilterer={true} customFilterer={customFilterFunction}
    useCustomFilterComponent={true} customFilterComponent={customFilterComponent}/>,
  document.getElementById('griddle')
);

The prop changeFilter gets passed to your customFilterComponent because it's the customFilterComponent prop of Griddle.

There is an example of custom filtering on the following page: http://griddlegriddle.github.io/Griddle/docs/customization/

See the "Component Customization" section.

发布评论

评论列表(0)

  1. 暂无评论