Created
April 5, 2016 12:39
-
-
Save rodcisal/99d082c5a8c7d34930cbaa04f06e6ad5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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