I am using react-table as data-grid. I am implementing table based search filtering. The filtering does not seem like working , as a result its returning empty results. I do not where I am going wrong.
Can someone help?
Help would be appreciated
Data format
let data =[ {id: 1, val1: "45GFSDSD", val2: "AKFHFDH83E3HHYE"},
{id: 2, val1: "46FDGDGDGDG", val2: "AKFHFDH83E3HFGD"},
{id: 3, val1: "56FDGGFGF", val2: "AERTFDH83E3HHYD"}
]
Component code
import * as React from 'react';
import ReactTable from 'react-table';
class MyTable extends React.Component {
constructor () {
super();
this.state = {
data: data, // data from API, structure has been shown above
search: ''
}
}
render () {
let data = this.state.data
if (this.state.search)
{
data = data.filter((value) => {
return value.val1.includes(search)||value.val2.includes(search)|| String(value.id).includes(search)
})
}
return (
<div>
Search:
<input value={this.state.search} onChange={e => this.setState({search: e.target.value})} />
<ReactTable data={data} columns={columns} />//column object
</div>
)
}
}