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

Parent node value is not included in the selected items #43

Closed
nghiado opened this issue Sep 11, 2017 · 12 comments
Closed

Parent node value is not included in the selected items #43

nghiado opened this issue Sep 11, 2017 · 12 comments

Comments

@nghiado
Copy link

nghiado commented Sep 11, 2017

I have couple questions/requests for your great component

  1. I have a use case that requires to get all selected values from the tree (not only leaf nodes).
    For example Frontend and Backend nodes in your first demo have their own ids, they should be included in the selected results.
  2. Is there any way we can add a flag to allow select/deselect child/parent node without updating other nodes? Think about use case like select everything under Programming except ReactJS
    I still want Programming and Front end checked but ReactJS unchecked..
    This also related to item 1 since I need to send Front end value back to backend.
    Thanks
@leovo2708
Copy link
Owner

Question 1: using TreeviewEventParser like in my example 5 https://leovo2708.github.io/ngx-treeview/. You can get list of checked from root to leaf.

Question 2: Yes, you can. You can update checked of your TreeviewItem object. But it will not update checked of parent, you must do this yourself. You should write a helper to handle this.

@nghiado
Copy link
Author

nghiado commented Sep 12, 2017

Thanks for quick resposne @leovo2708.
Yes, #1, I was thinking about create a custom TreeviewEventParser to return a flat list of selected items.
About #2, can you give an example?
What I was thinking is in TreeviewItemComponent

onCheckedChange = (skipChildrenCheck) => {
        const checked = this.item.checked;
        if (!_.isNil(this.item.children)&& !skipChildrenCheck) {
            this.item.children.forEach(child => child.setCheckedRecursive(checked));
        }

        this.checkedChange.emit(checked);
    }
    onChildCheckedChange(child: TreeviewItem, checked: boolean, skipParentUpdate) {
        if (this.item.checked !== checked && !skipParentUpdate) {
            let itemChecked = true;
            for (const tmpChild of this.item.children) {
                if (!tmpChild.checked) {
                    itemChecked = false;
                    break;
                }
            }

            this.item.checked = itemChecked;
        }

        this.checkedChange.emit(checked);
    }

I tried to override the onCheckedChange and onChildCheckedChange but the component is not exported from the lib so not so sure how I can achieve this.

@leovo2708
Copy link
Owner

If I support option {disabled: true, checked: false} for item ReactJS, does it rescue you?

@nghiado
Copy link
Author

nghiado commented Sep 12, 2017 via email

@leovo2708
Copy link
Owner

I think you can use itemTemplate. It can help you.

@nghiado
Copy link
Author

nghiado commented Sep 12, 2017

@leovo2708 I need a way to emit this event this.checkedChange.emit(checked); using itemTemplate without calling onCheckedChange and onChildCheckedChange.
I think this requires a minor change in TreeviewItemComponent and TreeviewItemTemplateContext.

@leovo2708
Copy link
Owner

Please help me to create pull request. Thanks.

@leovo2708
Copy link
Owner

Published in new version 1.2.2.

@arunkumar1811
Copy link

arunkumar1811 commented Oct 5, 2017

Hi,
"selectedChange" event has been fired when selecting Parent but the $event array is empty. But the expected would be event array with Parent node value.
I guess the problem is with binding the selected node in ngmodel

Its working as expected when I select child nodes. I'm using the latest verion 1.2.3.

Parent and child nodes can be selected independently by setting decoupleParentChild= true in the config.

@avtokey
Copy link

avtokey commented Apr 17, 2018

please get some example to get parent value(Id) in items. I think, It's very important for all developers.

Parent (value: 1) -- I need this value, but I think this component doesn't have such functionality.
--Child 1 (value: 2)
--Child 2 (value: 3)

@rwasan
Copy link

rwasan commented Feb 24, 2023

same issue please let me know if it's fixed

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

6 participants
@nghiado @avtokey @leovo2708 @arunkumar1811 @rwasan and others