I am making a react project in which I'm using table and I need to add a search functionality to it. Right now the table is populated with objects.
function createData(Estimate, ServiceProvider, Vehicle, Date, Amount, Status, Action) {
return {Estimate, ServiceProvider, Vehicle, Date, Amount, Status, Action};
}
const rows = [
createData('#10001', "Euro Motors", "2010 Toyota Corolla CE FWD", "January 28, 2021", "$395.11", "Approved",),
createData('#10002', "Auto Motors", "Some car model", "January 28, 2021", "$395.11", "Pending"),
createData('#10003', "Some other Motors", "Some other car model", "January 28, 2021", "$395.11", "Approved"),
]
const [tableData, setTableData] = useState(rows)
Right now I have search functionality for just ServiceProvider using this
const requestSearch = (searchedVal) => {
const filteredRows = rows.filter((row) => {
return row.ServiceProvider.toLowerCase().includes(searchedVal.toLowerCase());
});
setTableData(filteredRows);
};
but I need it for Estimate, ServiceProvider, Vehicle. How can I extend the functionality to all three so whatever the user searches in the search bar it checks all three columns and filters out rows with repeation.