khan4019/tree-grid-directive

Access object properties

Opened this issue · 5 comments

Hi,

the objects i use to generate the table contain sub objects e.g.

"foo":{"bar":"baz","x":"y"}

I try to access the property bar from this object:

{
        field: "foo.bar",
        displayName: "Foo Bar"
}

However, that doesn't work for some reason. It doesn't display anything. But if i do

{
        field: "foo",
        displayName: "Foo Bar"
}

it displays:

{"bar":"baz","x":"y"}

How can i get around that without changing the format of the JSON?

The field property isn't designed to be used for deep object traversal - it is simply the name of the property of the node.

You have two options I would say:

  1. you can "flatten" your nodes and construct a simple object
  2. you can define a cellTemplate for your node where you can access everythin from your object

Flattening is a bad idea imho, if you have a large set of nodes. Interestingly, i can't make the cellTemplate approach work.

What are you concrete problems with the cellTemplate?

Inside the template you can access your node via row.branch. That gives you the single node.

Shortened Example:

...
cellTemplate: "<span>{{row.branch.foo.bar}}</span>",
...

Ah, that did the trick. I was missing the surrounding span, so all i got was an error.

Thank you :)

Yeah, you need one html element to let angular render the whole thing - otherwise it complains ;-)