How to use generic search with strapi-v4 and useTable
Hi 👋
I am listing the customers from my database with useTable hook from AntD and Strapi-v4 as data provider. I would like to implement a single search field to filter over the name, surname, email, ...
I could use the onSearch property, but it only works on a single field and the API URL is always in the following format http://apiurl/customers?filters[$field][$operator]=$value.
With Strapi, one could use the "_q" URL parameters to search over all table fields, e.g., http://apiurl/customers?_q=mySeachString . Any idea if and how I could implement this with useTable?
Cheers
6 Replies
fascinating-indigo•2y ago
Hey @npanti I think this document can help you. https://refine.dev/docs/advanced-tutorials/search/table-search/
Table Search | refine
We can make extensive search / filter operations using the useTable hook on the listing pages.
inc-lavender•2y ago
Thanks @yildirayunlu, but it seems there is no way to make a search with the _q parameter of Strapi.
Without reinventing the wheel and rewriting a new useTable hook. The easiest way seems to use the "or" crud operator over all elements of my table one by one, like this.
fascinating-indigo•2y ago
Hey @npanti I think you dont need to write the fields one by one.
list.tsx
Request:
https://api.strapi.refine.dev/posts?_limit=10&_sort=id:desc&_start=0&=&_q=test
inc-lavender•2y ago
This would work with Strapi version 3 but not with Strapi version 4, for which the request would be something like this, following your example:
Unless there is some configuration, I am missing.
fascinating-indigo•2y ago
Yes, I haven't tested it for v4 😦
The best use for now seems to be to write all the fields.
inc-lavender•2y ago
Thanks for confirming. Happy holidays! 🎄 🎆