I have a three dropdowns country,state,task with some values populated from an array and button for search which works based on the dropdown selection. The first time I choose a value from the task dropdown menu ="verify" the grid(an array of values) is filtered on handlesubmit event but when I reselect another value from the task dropdown ="add" the grid is looking only from the previous filtered list and not returning any records
I think I am unable to reset the array on every submit(handlesubmit is the event I m calling on the button click) of that search button. Below is the code where I need to reset the searchtasks to initiatetasks:
class Initiate extends Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
var data = [{
id: 1,
country: "USA",
task: "Verify ",
state: "Alaska"
},
{
id: 2,
country: "USA",
task: "Add ",
state: "Delaware"
},
{
id: 3,
country: "USA",
task: "Verify ",
state: "Delaware"
}];
this.state = {
searchtasks: data,
initialstate :data,
country: Country [0],
task: Task [0],
state: States[0]
};
}
handleChange(event) {
this.setState({ value: event.target.value });
}
handleSubmit(event) {
event.preventDefault();
this.setstate({searchtasks: this state.initialstate});
const sa = Country[event.target.ddlcountry.value].label;
const tt = Task [event.target.ddltask.value].label;
const st = States[event.target.ddlstates.value].label;
if (sa !== "Select Country")
{
this.setState({ searchtasks: this.state.searchtasks.filter(item => item.country === sa) });
}
if (tt !== "Select Task") {
this.setState({ searchtasks: this.state.searchtasks.filter(item => item.task === tt) });
}
if (st !== "Select State") {
this.setState({ searchtasks: this.state.searchtasks.filter(item => item.state === st) });
}
}
//formats the cost
priceFormatter(cell, row) {
return '<i class="glyphicon glyphicon-usd"></i> ' + cell;
}
// renders the component
render() {
const selectRowProp = {
mode: "checkbox",
clickToSelect: true
};