Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to filter based on a nested field #42

Closed
wants to merge 1 commit into from

Conversation

remiremi
Copy link
Contributor

With this fix you could have a list filter that filters on a nested object field, for example doing

const ProductListFilter = (props: any) => (
  <Filter {...props}>
    <SelectInput
      label="Status"
      source="category.status"
      choices={[
        { id: "in_production", name: "In Production" },
        { id: "planned", name: "Planned" },
        { id: "retired", name: "Retired" }
      ]}
      emptyText="All"
      alwaysOn
    />
  </Filter>
);

export const ProductList = (props: any) => (
  <List
    {...props}
    filters={<ProductListFilter />}
    sort={{ field: "planting_date", order: "ASC" }}
    filterDefaultValues={{ category: { status: "in_production" } }}
  >
    .....

@pankgeorg
Copy link
Contributor

pankgeorg commented Feb 19, 2021

Good job@remiremi! Thank you for that, I wanted exactly the same feature. Though, I think something in this PR seems wrong; the generated query for category.status@_ilike is {category: {"status@_ilike": {_eq: <value>}}} and not {category: {"status": {_ilike: <value> }}}

@pankgeorg
Copy link
Contributor

I do the same here, following a different path from your approach: #47

@praveenweb
Copy link
Member

@remiremi - Thanks for the PR. This looks good. But as @pankgeorg mentioned, the query generation had a minor issue.

So I have merged #47 and closing this in favour of that.

@praveenweb praveenweb closed this May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants