Search code examples
react-adminsupabase

How can I search Supabase database in React Admin using ilike instead of eq filter?


I have a react admin application linked to my supabase database. I have a posts table in this database. My aim is to be able to search the titles of these posts via react admin. For example, I have two posts {id:1, title: "first post"} and {id:2, title: "second post"}. When I do a search for "second" using this code :

const postFilters = [
    <TextInput source="title" label="Search by title" alwaysOn />,
];

export const PostList = () => (
    <List filters={postFilters} >
      <Datagrid >
        <TextField source="id" />
        <TextField source="title" />
        <EditButton />
        <ShowButton />
      </Datagrid>
    </List>
);

It doesn't return any results because it wants a strict equality. If I type "second post" as search term, it will give me the result expected.

I have tried to change my by a like that : <SearchInput source="title" alwaysOn /> but it don't change anything.

I can see on my database logs this url : /post?title=eq.second. I think if I can be able to change title=eq.second to somthing like title=ilike.second it should work but I don't know how to do it.


Solution

  • Thank you for giving me the idea to check the source code of my DataProvider @MaxAlex.
    I use ra-data-postgrest and after reading its README in node_modules, I saw that we can simply do this : <TextInput source="title@ilike" label="Search by title" alwaysOn />.