Skip to content

Instantly share code, notes, and snippets.

@rodcisal
Created April 5, 2016 12:39
Show Gist options
  • Save rodcisal/99d082c5a8c7d34930cbaa04f06e6ad5 to your computer and use it in GitHub Desktop.
Save rodcisal/99d082c5a8c7d34930cbaa04f06e6ad5 to your computer and use it in GitHub Desktop.
import React from "react";
export default class Table extends React.Component {
constructor() {
super();
this.state = { query: '', filteredData: undefined };
}
searching = () => {
this.search(this.refs.input.value);
}
search(query) {
var filteredData = [];
this.props.data.forEach( (account) => {
if ( account.Account.toLowerCase().indexOf(query) != -1 ) {
filteredData.push(account);
}
});
console.log(filteredData);
this.setState({ filteredData: filteredData });
}
renderResults() {
var rows = [];
if (this.state.filteredData) {
this.state.filteredData.forEach( (result) => {
rows.push(<tr><td>{ result.Account } </td><td> {result.Kam} </td> </tr>)
})
}
return rows;
}
render() {
return (
<div class="results">
<input type="text" ref="input" onChange={this.searching}/>
<div class="search-results">
<table>
{this.renderResults()}
</table>
</div>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment