angular-tree-component icon indicating copy to clipboard operation
angular-tree-component copied to clipboard

Can I have DisplayField with more than 1 values?

Open LynnWong5596 opened this issue 5 years ago • 2 comments

Im wondering can I assign DisplayField with more than 1 values? For example, the normal situation is

nodes = [
    {
      _id: '1',
      title: 'root1',
      nodes: [{_id: '3', title: 'child1'}]
    },
    {
      _id: '2',
      title: 'root2'
    }
  ];

  options: ITreeOptions = {
    idField: '_id',
    displayField: 'title',
    childrenField: 'nodes'
  };

What Im try to achieve is something like

nodes = [
    {
      _id: '1',
      title: 'root1',
      nodes: [{_id: '3', title: 'child1'}]
    },
    {
      _id: '2',
      titleOption: 'root2',
      nodes: [{_id: '4', titleOption: 'child2'}]
    }
  ];

  options: ITreeOptions = {
    idField: '_id',
    displayField: 'title' || 'titleOption',
    childrenField: 'nodes'
  };

any way to achieve it?

LynnWong5596 avatar Feb 14 '20 04:02 LynnWong5596

I think we can have a displayField that's a function that gets the TreeNode. So something like:

displayField: (node) => node.data.title || node.data.titleOption

If someone is willing to create a PR for this and add tests I will merge

adamkleingit avatar Feb 14 '20 07:02 adamkleingit

Is it possible to build displayField as below?

displayField: (node) => { return ${node.data.someNumber} ${node.data.title}}

Prabukmca avatar Mar 05 '20 08:03 Prabukmca