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

Can I have DisplayField with more than 1 values? #793

Open
LynnWong5596 opened this issue Feb 14, 2020 · 2 comments · May be fixed by #945
Open

Can I have DisplayField with more than 1 values? #793

LynnWong5596 opened this issue Feb 14, 2020 · 2 comments · May be fixed by #945

Comments

@LynnWong5596
Copy link

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?

@adamkleingit
Copy link
Contributor

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

@Prabukmca
Copy link

Is it possible to build displayField as below?

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

IBlackI pushed a commit to IBlackI/angular-tree-component that referenced this issue Jun 30, 2022
Functions can be used to retrieve the value of Fields for nodes.

resolve CirclonGroup#793
@IBlackI IBlackI linked a pull request Jun 30, 2022 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants