Reacr-Admin, OData: how to filter a list by nested data

184 views Asked by At

I receive the following data:

[
  {
    userId:1,
    user: {
      id: 1,
      email: gmail1,
      personId: 55,
      person: {
        id: 55,
        firstName: "Adams"
      }
    }
  },
  {
    userId:2,
    user: {
      id: 2,
      email: gmail2,
      personId: 43, 
      person: {
        id: 43,
        firstName: "john"
      }
    }
  }
]

And the problem is that because of this design, I cannot filter the data by the firstName field. Can you help make filtering correctly means React-Admin

1

There are 1 answers

1
hgb123 On

Just access properties

const filtered = data.filter((d) => d.user.person.firstName === term)

const data = [
  {
    userId: 1,
    user: {
      id: 1,
      email: "gmail1",
      personId: 55,
      person: {
        id: 55,
        firstName: "Adams",
      },
    },
  },
  {
    userId: 2,
    user: {
      id: 2,
      email: "gmail2",
      personId: 43,
      person: {
        id: 43,
        firstName: "john",
      },
    },
  },
]

const term = "john"

const filtered = data.filter((d) => d.user.person.firstName === term)

console.log(filtered)