title: Global search data table react
body: <p>I need to create global search in my data , and go throughout all objects in data and update the state of the table. What is the best way to do this? In my state I receive data array, I've got two method to handle this behavior. Can not find what I mess? I try to use two method <strong>handleSearch</strong> and <strong>handleSearchTest</strong></p>
  
  <pre><code> const data = [
      { key: 1, deviceType: 'Tag', deviceID: 1, name:'Tag For sending an ', location: 'Room_104', status: 'assigned'},
      { key: 2, deviceType: 'Tag', deviceID: 2, name:'Tag For sending an ', location: 'Room_104', status: 'assigned'},
      { key: 3, deviceType: 'Tag', deviceID: 3, name:'Tag For sending an ', location: 'Room_104', status: 'assigned'},
      { key: 5, deviceType: 'AccessPoint', deviceID: 4, name:'AP_2 ', location: 'Room_104', status: 'offline'},
      { key: 4, deviceType: 'AccessPoint', deviceID: 5, name:'AP_1', location: 'Room_104', status: 'offline'},
  ]
  
  
  class EnhancedTable extends Component {
      state = {
          selected: [],
          data,
          order: {
              direction: 'asc',
              by: 'deviceID',
          },
          search: '',
      }
  
      handleSearch = (event, value) =&gt; {
          // debugger
          const {data} = this.state
          let filteredDatas = []
          filteredDatas = data.filter(e =&gt; {
              let mathedItems = Object.values(e)
              let returnedItems
              mathedItems.forEach(e =&gt; {
                  const regex = new RegExp(event.target.value, 'gi')
                  if (typeof e == 'string')
                      returnedItems = e.match(regex)
              })
              return returnedItems
          })
          this.setState({data: filteredDatas, search: event.target.value})
      }
  
      fuzzyContains = (text, search) =&gt; {
          if (!text)
              return false
          if (!search)
              return true
  
          search = search.toLowerCase()
          text = text.toString().toLowerCase()
  
          let previousLetterPosition = -1
  
          return search.split('').every(s =&gt; {
              previousLetterPosition = text.indexOf(s, previousLetterPosition + 1)
  
              return previousLetterPosition !== -1
          })
      }
  
      handleSearchTest = (e, search) =&gt; {
          const {data} = this.state
  
          let result = data.filter(x =&gt; Object.keys(x).some(key =&gt;
              this.fuzzyContains(x[key], search)
          ))
  
          this.setState({data: result})
      }
  
  
      render = () =&gt; {
  
          const {selected, data, search, order} = this.state
  
          return (
              &lt;Paper&gt;
                  &lt;Table
                      data={data}
                      search={search}
                      onSearch={this.handleSearchTest}
                  /&gt;
              &lt;/Paper&gt;)
      }
  }
  export default EnhancedTable
  </code></pre>