# HG changeset patch # User Frank Bessou <frank.bessou@logilab.fr> # Date 1614246224 -3600 # Thu Feb 25 10:43:44 2021 +0100 # Node ID ee0b249da2fc1c8d492a0400efb9a5ad33cd6be1 # Parent 7c9728f4fb2bd851492e3935a94369a1d58a0cf1 feat(getList): implement filtering on text attributes value diff --git a/packages/demo/src/App.tsx b/packages/demo/src/App.tsx --- 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,8 +54,14 @@ </Edit> ); +const MuseumFilter = (props: Omit<FilterProps, "children">) => ( + <Filter {...props}> + <SearchInput source="name" alwaysOn /> + </Filter> +); + 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 --- 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]);