Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple filters for Griddle v1 #630

Open
hkeshani opened this issue Apr 4, 2017 · 6 comments
Open

Multiple filters for Griddle v1 #630

hkeshani opened this issue Apr 4, 2017 · 6 comments

Comments

@hkeshani
Copy link

hkeshani commented Apr 4, 2017

Is there a working example showing how to implement multiple filters for Griddle v.1, as was shown in the v. 0.x docs https://griddlegriddle.github.io/v0-docs/customization.html ?

@jovanni-hernandez
Copy link

jovanni-hernandez commented Apr 12, 2017

This is also of great interest to me, I've been trying to figure out how to add multiple filters from a plugin I've made, but I don't see any obvious ways of doing so. It appears that the core functionality only allows one filter at a time. Also column based filtering would be amazing.

@davidpelayo
Copy link

davidpelayo commented Apr 20, 2017

I think this is a must have and looking forward to see how to plug-in into my griddle table. Anyone with some working example? Related?

@davidpelayo
Copy link

I've added by the way a modification in my forked repo in a way I can provide to a custom <Filter /> component an object to the setFilter action hook, being then responsibility of the plugins.Local's dataFilteredSelector to consider whether the filter is a plain string or an object.

Please any suggestion, enhancement or doubt, let's discuss it.

Therefore my custom Filter component:

class CustomFilter extends Component {
  constructor(props) {
    /* ... */

    this.state = {
      filter1: '',
      filter2: ''
    };
  }

  setFilter1(e) {
    this.setState({
      filter1: e.target.value
    }, () => {
      this.props.setFilter({
        filter1: this.state.filter1
      });
    });
  }

  setFilter2(e) {
    this.setState({
      filter2: e.target.value
    }, () => {
      this.props.setFilter({
        filter2: this.state.filter2
      });
    });
  }

  render() {
    return (
      <div className="custom__filters">
        <input
          type="text"
          name="filter"
          placeholder="Filter 1"
          value={this.state.filter1}
          onChange={this.setFilter1}
          style={this.props.style}
          className={cx(this.props.className, 'custom-filters__filter')} />
        <input
          type="text"
          name="filter"
          placeholder="Filter 2"
          value={this.state.filter2}
          onChange={this.setFilter2}
          style={this.props.style}
          className={cx(this.props.className, 'custom-filters__filter')} />
      </div>
    );
  }
}

CustomFilter.propTypes = {
  /* ... */
};

export default CustomFilter;

The dataFilteredSelector will consider we have two columns on our dataset identified by the keys: filter1 and filter2, filtering the data as follows:

export const filteredDataSelector = createSelector(
  dataSelector,
  filterSelector,
  (data, filter) => {
    return data.filter(row  => {
      return Object.keys(row.toJSON())
        .some(key => {
          if (typeof filter === 'string') {
            return row.get(key) && row.get(key).toString().toLowerCase().indexOf(filter.toLowerCase()) > -1
          }

          return row.get(key) && typeof filter[key] === 'string' && row.get(key).toString().toLowerCase().indexOf(filter[key].toLowerCase()) > -1;
        })
      })
  }
);

@hkeshani
Copy link
Author

Thanks so much for this! I'll give it a try and report back.

@davidpelayo
Copy link

davidpelayo commented May 4, 2017

Related to #177.
Related to #66.

@jtlindsey
Copy link

jtlindsey commented Sep 27, 2017

Any update on being able to filter by column? I'm catching the events ..onFilter but i'm not sure what to do with it when i get it. For server side i can filter, but for client side, I'm not sure if I should be modifying some existing functionality or using my own client side filter function.
Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants