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

Nested JSON doesn't work #990

Open
johannydls opened this issue Apr 5, 2019 · 3 comments
Open

Nested JSON doesn't work #990

johannydls opened this issue Apr 5, 2019 · 3 comments

Comments

@johannydls
Copy link

On my JSON, I have this:

{
  "employees": [
    {
      "id": 1,
      "name": "Jason Bourne",
      "employeeId": "us2323",
      "city": "New York",
      "contact": {
        "email": "jason.bourne@mail.com",
        "phone": "5511922118522"
      }
    },
    {
      "id": 2,
      "name": "Mary",
      "employeeId": "us6432",
      "city": "San Jose",
      "contact": {
        "email": "mary@mail.com",
        "phone": "5511974545522"
      }
    },

On my settings, I have this:

settings = {
    columns: {
      id: {
        title: 'ID'
      },
      name: {
        title: 'Name'
      },
      employeeId: {
        title: 'Employee No.'
      },
      
      "contact.email":{
        title: 'Contact'
      }
    },
    actions: {
      add: false
    }
  };

In the rendered table, nothing is shown in the Contact field.

If I change "contact.email" to just "contact", in the table processed I have [object Object]. And keeping it that way, if I add "valuePrepareFunction" to get the "email", in the rendered table the correct value is shown. However, I can not filter because the value remains [object Object] in the filter. If I try to edit, the [object Object] value is also shown in the input field.

Is there any way I can list nested objects, filter by the correct value (instead of [object Object]) or edit?

@johannydls johannydls changed the title Nested JSON does'nt work Nested JSON doesn't work Apr 5, 2019
@15206125206
Copy link

I met the same problem, how to solve it?

@alshoja
Copy link

alshoja commented May 13, 2019

can anyone please help with this problem got the same issue for me??

@johannydls
Copy link
Author

johannydls commented May 13, 2019

I met the same problem, how to solve it? (@15206125206)

can anyone please help with this problem got the same issue for me?? (@alshoja)

I solved this problem as follows:

contact: {
        title: "Contact",
        valuePrepareFunction: (contact) => {
          return contact.email;
        },
        filterFunction(contact?: any, search?: string): boolean {
          let match = true;
          Object.keys(contact).map(u => contact.email).filter(it => {
            match = it.toLowerCase().includes(search);
          });

          if (match || search === '') {
            return true;
          } else {
            return false
          }
        },
        filter: true,
        compareFunction: (direction: any, a: any, b: any) => {
          let first = typeof a.email === 'string' ? a.email.toLowerCase(): a.email;
          let second = typeof b.email === 'string' ? b.email.toLowerCase(): b.email;

          if (first < second) {
            return -1 * direction;
          }
          if (first > second) {
            return direction;
          }
          return 0;
        }
      }

The filterFunction and compareFunction is to filter/compare exactly by email value, not by the value "[Object object]";

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

No branches or pull requests

3 participants