简体   繁体   中英

how to filter all columns of html table using react js?

I am creating custom data table. I have added sorting, pagination but unable to do searching on all columns. Here is the URL of what i have created

https://codesandbox.io/s/yv48o7onwj

Data array contains uppercase words and integers.

How to implement filter/search on all columns using single input box?

You can do it using Array.filter

const filtered = products.filter(item => (
   item.id === searchString ||
   item.name === searchString ||
   item.price === searchString ||
   item.qa === searchString ||
   item.qr === searchString ||
   item.vendor === searchString
));

and then replace {products.map(item => { on line 326 to {filtered.map(item => {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM