resources/assets/js/components/Home.js
// the state, filter and ref must be defined properly with same name and variable name
the state, filter and ref must be defined properly with same name and variable name
the state filter and ref must be defined properly with same name and variable name
filterClient(){
          this.sleep(1000).then(()=>{
            var filteredData = this.state.clients
            for (let [key, value] of Object.entries(this.state.formdata)) {
              if(this.refs[key]){
                if (Array.isArray(value)){
                  if (value[0] !== "" && value[0] && value[1] !== "" && value[1]){
                     })
                       date: new Date(value[1]),
                       comparator: '<='
                     })
                    filtering based on the tempClients state so the table will update as well
                    filteredData = filteredData.filter(function(values){
                        return new Date(values[key]) >= new Date(value[0]) && new Date(values[key]) <= new Date(value[1])
                    })
                  }
                   else{
                     this.refs[key].cleanFiltered()
                     this.setState({tempClients:this.state.clients})
                   }
                }else{
                  if (value !== "" && value !== 0 && value !== -1 && value){
                    console.log("value",value)
                    this.refs[key].applyFilter(value)
                    filteredData = filteredData.filter(function(values){
                      3. string.search
                      var string1 = values[key];
                      var expr = value;
                      if(string1.indexOf(expr) !== -1){
                        console.log("values",values[key])
                        console.log("value",value)
                      }
                      console.log(string1.indexOf(expr) !== -1)
                      return string1.indexOf(expr) !== -1
                    })
                  }else{
                    this.refs[key].cleanFiltered()
                  }
                }
              }
            }
            this.setState({tempClients:filteredData})
          })
        }
filterClient ( ) { this . sleep ( 1000 ) . then ( ( ) => { var filteredData = this . state . clients for ( let [ key , value ] of Object . entries ( this . state . formdata ) ) { if ( this . refs [ key ] ) { if ( Array . isArray ( value ) ) { if ( value [ 0 ] !== "" && value [ 0 ] && value [ 1 ] !== "" && value [ 1 ] ) { filteredData = filteredData . filter ( function ( values ) { return new Date ( values [ key ] ) >= new Date ( value [ 0 ] ) && new Date ( values [ key ] ) <= new Date ( value [ 1 ] ) } ) } } else { if ( value !== "" && value !== 0 && value !== - 1 && value ) { filteredData = filteredData . filter ( function ( values ) { var string1 = values [ key ] ; var expr = value ; if ( string1 . indexOf ( expr ) !== - 1 ) { console . log ( "values" , values [ key ] ) console . log ( "value" , value ) } console . log ( string1 . indexOf ( expr ) !== - 1 ) return string1 . indexOf ( expr ) !== - 1 } ) } else { } } } } this . setState ( { tempClients : filteredData } ) } ) }
the state, filter and ref must be defined properly with same name and variable name
the state filter and ref must be defined properly with same name and variable name
// do something with key|value // if the column is exist as the column may not exist in some of the roles // if it is an array then it is a ranged filter such as date // index 0 is bottom value and index 1 is upper value // this.refs[key].applyFilter({ //   date: new Date(value[0]), //   comparator: '>=' // // }) // this.refs[key].applyFilter({ //   date: new Date(value[1]), //   comparator: '<=' // // }) //filtering based on the tempClients state so the table will update as well // else{ //   this.refs[key].cleanFiltered() //   //this.setState({tempClients:this.state.clients}) // } //console.log("value",value) //this.refs[key].applyFilter(value) //3. string.search //this.refs[key].cleanFiltered()