fair-rose
fair-rose•2y ago

filter on useList

Hello, I am trying to apply filters on useList data query from API but looks like filter is not working. I want the list of users with "admin" role. interface User { _id: string; name: string; role: string; } const { data: Admin } = useList<User>({ resource: "users", config: { hasPagination: false, filters: [ { field: "role", operator: "eq", value: "admin", }, ], }, }); const admin: User[] = Admin?.data ?? []; console.log("admin:", admin); and the result as the screenshot hasPagination and pagination are working fine but filters and sort are not. I checked the documentation but still not sure what is wrong with my code. https://refine.dev/docs/api-reference/core/hooks/data/useList/ Thank you in advance.
useList | refine
useList is an extended version of TanStack Query's useQuery. It supports all the features of useQuery and adds some extra features.
No description
4 Replies
kapa.ai
kapa.ai•2y ago
Hey @jkk980! I'm the kapa.ai support bot. I've searched through the docs to try to answer your question. :wave:
kapa.ai
kapa.ai•2y ago
---------------------- It looks like you are using the correct syntax for applying filters on useList data query from API. However, it is possible that the data you are trying to filter is not in the expected format. The useList hook supports the filtering feature. You can pass the filters property to enable filtering. To handle filtering, the useList hook passes the filters property to the getList method from the dataProvider. The filters property should be configured via field, operator and value properties. The operator property should be one of the supported operators listed in the documentation (https://refine.dev/docs/2.xx.xx/api-references/hooks/data/useList). It is also possible that the query is not running automatically. To disable query from running automatically you can set enabled to false in the queryOptions property.
import { useList } from "@pankod/refine";

const postListQueryResult = useList<IPost>({
resource: "posts",
queryOptions: { enabled: false },
});
import { useList } from "@pankod/refine";

const postListQueryResult = useList<IPost>({
resource: "posts",
queryOptions: { enabled: false },
});
If you are still having trouble, please refer to the react-query docs (https://react-query.tanstack.com/reference/useQuery) for further information. I hope this helps! ----------------------
kapa.ai
kapa.ai•2y ago
<@216369213219012609> kapa.ai is still learning and improving, please let us how it did by reacting below
Omer
Omer•2y ago
Hey @jkk980 👋 , It seems to be related to your DataProvider. Have you correctly configured the API configuration for filtering in your DataProvider? Please follow our DataProvider tutorial at https://refine.dev/docs/tutorial/understanding-dataprovider/index/.
1. Data Provider | refine
The data provider unit is optional for the tutorial and can be skipped to next unit - Adding CRUD PagesAdding CRUD PagesAdding CRUD PagesAdding CRUD PagesAdding CRUD Pages