Skip to content

Instantly share code, notes, and snippets.

@vishnu-saini
Created December 5, 2019 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishnu-saini/16406b99a84a77265580c333cd515df5 to your computer and use it in GitHub Desktop.
Save vishnu-saini/16406b99a84a77265580c333cd515df5 to your computer and use it in GitHub Desktop.
import React, {Component} from "react";
import ReactDOM from "react-dom";
export default class PartialMatchFilter extends Component {
constructor(props) {
super(props);
this.state = {
text: ''
};
this.valueGetter = this.props.valueGetter;
this.onChange = this.onChange.bind(this);
}
isFilterActive() {
return this.state.text !== null && this.state.text !== undefined && this.state.text !== '';
}
doesFilterPass(params) {
return this.state.text.toLowerCase()
.split(" ")
.every((filterWord) => {
return this.valueGetter(params.node).toString().toLowerCase().indexOf(filterWord) >= 0;
});
}
getModel() {
return {value: this.state.text};
}
setModel(model) {
this.state.text = model ? model.value : '';
}
afterGuiAttached(params) {
this.focus();
}
focus() {
window.setTimeout(() => {
let container = ReactDOM.findDOMNode(this.refs.input);
if (container) {
container.focus();
}
});
}
componentMethod(message) {
alert(`Alert from PartialMatchFilterComponent ${message}`);
}
onChange(event) {
let newValue = event.target.value;
if (this.state.text !== newValue) {
this.setState({
text: newValue
}, () => {
this.props.filterChangedCallback();
});
}
}
render() {
let style = {
border: "2px solid #22ff22",
borderRadius: "5px",
backgroundColor: "#bbffbb",
width: "200px",
height: "50px"
};
return (
<div style={style}>Filter: <input style={{height: "20px"}} ref="input" value={this.state.text}
onChange={this.onChange} className="form-control"/></div>
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment