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

[Feature] td-data-table to handle column data for JSON nested objects #189

Closed
bzmillerboy opened this issue Dec 13, 2016 · 1 comment
Closed

Comments

@bzmillerboy
Copy link

When using the <td-data-table [data]="data" [columns]="columns" > it's required you specify your column values as strings like:

  columns: ITdDataTableColumn[] = [
    { name: 'name', label: 'Name' },
    { name: 'dob', label: 'Date of Birth' },
    { name: 'age', label 'Age', numeric: true },
  ];

However, when your JSON is not flat and is structured with nested objects like:

  data: any[] = [
    {
      name: {
        firstName: "Jane",
        lastName: "Doe"
      },
      dob: "10/20/1982",
      age: "34",
    }
  ]

This array of columns does not work.

The work around to this would be to use the atomic parts of the <td-data-table> and define this in your template with {{ name.first}} {{ name.last }}. However, it would be great if the component property could handle nested objects.

Issue raised by @kmiyatake in the gitter chat room.

@jeremysmartt
Copy link
Collaborator

jeremysmartt commented Dec 13, 2016

I think the best way to handle this is to have a flag on the column to indicate that you want to use a nested json object. If we allow this:

columns: ITdDataTableColumn[] = [
    { name: 'name.firstname', label: 'First Name' },
    { name: 'dob', label: 'Date of Birth' },
    { name: 'age', label 'Age', numeric: true },
  ];

we wouldn't know by the string 'name.firstname', do they want the object attribute name.firstname or the actual string value "name.firstname".

Having a flag like:

columns: ITdDataTableColumn[] = [
   { name: 'name.firstname', label: 'First Name', nested: true|false },
   { name: 'dob', label: 'Date of Birth' },
   { name: 'age', label 'Age', numeric: true },
 ];

Will allow us to distinguish between these two cases. Also the nested flag should be an optional parameter and by default would be true, as probably most cases would expect name.firstname to mean the object.

@emoralesb05 emoralesb05 added this to the Alpha 0.10 milestone Dec 23, 2016
@emoralesb05 emoralesb05 self-assigned this Dec 23, 2016
kyleledbetter pushed a commit that referenced this issue Dec 26, 2016
…e. closes(#189) (#207)

* support for nested objects + changed detection to OnPush for efficiency

* exported missing  interface ITdDataTableSelectEvent

* added refresh functon to API and README

* added example for nested objects

* workaround for angular/components#1825

* fixed tslint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants