score:0

you can do this sending the search type also in request and based on that search type you can give conditions.to do this:- first add one more state in your table component.

const [searchtype, setsearchtype] = usestate("1");

after change change select element to

<select aria-label=".form-select-sm example" value={searchtype} onchange={(event) => setsearchtype(event.target.value)}>
   <option selected value="1">all</option>
   <option value="2">name</option>
   <option value="3">phone</option>
</select>

now in getusers method pass serachtype and after that send as querystring in url. based on searchtype get the data.

score:0

seems that you haven't implement the "search by column" in your back-end. you should send the column type along with the search keyword in your request query. and in your back-end code

const { search, column } = req.query;

then update the $or dynamically.

const all = [
        { name: { $regex: search } },
        { phone: { $regex: search } },
];
const users = await usermodel.find({
    $or: column != null ? all.filter((item) => object.keys(item)[0] === column) : all,
})

note: you should validate if the column value is valid in a middleware.


Related Query

More Query from same tag