khan4019 / tree-grid-directive

Need one or more maintainer for this! comment or email me if you are interested
http://khan4019.github.io/tree-grid-directive/test/treeGrid.html
347 stars 183 forks source link

Access object properties #136

Open SoftCreatR opened 7 years ago

SoftCreatR commented 7 years ago

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?

torsten-sauer commented 7 years ago

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
SoftCreatR commented 7 years ago

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

torsten-sauer commented 7 years ago

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>",
...
SoftCreatR commented 7 years ago

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

Thank you :)

torsten-sauer commented 7 years ago

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