diff --git a/packages/demo/src/App.tsx b/packages/demo/src/App.tsx index 7c9728f4fb2bd851492e3935a94369a1d58a0cf1_cGFja2FnZXMvZGVtby9zcmMvQXBwLnRzeA==..ee0b249da2fc1c8d492a0400efb9a5ad33cd6be1_cGFja2FnZXMvZGVtby9zcmMvQXBwLnRzeA== 100644 --- a/packages/demo/src/App.tsx +++ b/packages/demo/src/App.tsx @@ -4,6 +4,9 @@ Resource, List, Datagrid, + Filter, + FilterProps, + SearchInput, TextField, NumberField, ReferenceField, @@ -51,4 +54,10 @@ </Edit> ); +const MuseumFilter = (props: Omit<FilterProps, "children">) => ( + <Filter {...props}> + <SearchInput source="name" alwaysOn /> + </Filter> +); + const MuseumList = (props: ListProps) => ( @@ -54,5 +63,5 @@ const MuseumList = (props: ListProps) => ( - <List {...props}> + <List {...props} filters={<MuseumFilter />}> <Datagrid rowClick="show"> <NumberField source="id" /> <TextField source="name" /> diff --git a/packages/ra-cubicweb/src/index.ts b/packages/ra-cubicweb/src/index.ts index 7c9728f4fb2bd851492e3935a94369a1d58a0cf1_cGFja2FnZXMvcmEtY3ViaWN3ZWIvc3JjL2luZGV4LnRz..ee0b249da2fc1c8d492a0400efb9a5ad33cd6be1_cGFja2FnZXMvcmEtY3ViaWN3ZWIvc3JjL2luZGV4LnRz 100644 --- a/packages/ra-cubicweb/src/index.ts +++ b/packages/ra-cubicweb/src/index.ts @@ -20,7 +20,7 @@ schema: S ): DataProvider { return { - getList: async (resource: ETypesNames<S>, { pagination, sort }) => { + getList: async (resource: ETypesNames<S>, { pagination, sort, filter }) => { const sortAttribute = sort.field === "id" ? "eid" : sort.field; const attributesNames = ["eid", ...Object.keys(schema.etypes[resource])]; const selection: string[] = []; @@ -34,6 +34,14 @@ sortvariable = variable; } }); + + // Handle filters + restrictions.push( + ...Object.entries(filter).map(([attrName, attrValue]) => { + return `EXISTS(X ${attrName} ~= '%${attrValue}%')`; + }) + ); + const total = await rqlClient .queryRows(`Any Count(${selection[0]}) WHERE ${restrictions.join(",")}`) .then((rows) => rows[0][0]);