react-table-filter-2
Version:
91 lines (84 loc) • 2.58 kB
JavaScript
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import SampleData from './sampleData.json';
import TableFilter from '../lib/bundle.js';
import { } from './example.scss';
import { } from '../lib/styles.css';
class SimpleExample extends Component {
constructor(props) {
super(props);
this.state = {
'episodes': SampleData._embedded.episodes,
};
this._filterUpdated = this._filterUpdated.bind(this);
this.clearFilter = React.createRef()
}
btnFunction = () => {
console.warn(this.clearFilter)
// const visibleFiltersValues = this.state.episodes.filter((filterItem) => filterItem).map((filterItem) => {return filterItem.name;})
// this.clearFilter.current._clearColFilter(visibleFiltersValues, 'name')
}
_filterUpdated(newData, filtersObject) {
this.setState({
'episodes': newData,
});
}
render() {
const episodes = this.state.episodes;
const elementsHtml = episodes.map((item, index) => {
return (
<tr key={'row_' + index}>
<td className="cell">
{item.name}
</td>
<td className="cell">
{item.season}
</td>
<td className="cell">
{item.number}
</td>
</tr>
);
});
return (
<div>
<div className="nav-bar">
<div className="container">
React Table Filters
</div>
</div>
{/* <button onClick={this.btnFunction}>TEST</button> */}
<div className="examples">
<div className="basic">
<h3 className="header">Basic Usage</h3>
<table className="basic-table">
<thead>
<TableFilter
rows={episodes}
onFilterUpdate={this._filterUpdated}
ref={this.clearFilter}>
<th key="name" filterkey="name" className="cell" casesensitive={'true'} showsearch={'true'}>
Name
</th>
<th key="season" filterkey="season" className="cell">
Season
</th>
<th key="number" filterkey="number" className="cell" alignleft={'true'}>
Number
</th>
</TableFilter>
</thead>
<tbody>
{elementsHtml}
</tbody>
</table>
</div>
</div>
</div>
);
}
}
ReactDOM.render(
<SimpleExample />,
document.getElementById('mainContainer')
);