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

load items from data, DownlineTreeviewItem selection by order not work #340

Open
dmaf87 opened this issue Feb 16, 2023 · 0 comments
Open

Comments

@dmaf87
Copy link

dmaf87 commented Feb 16, 2023

Hi @leovo2708,

In your advanced example with DownlineTreeviewItem selection by order not work if we load items from unordered items (it will always sorted by value and product category in onSelectedChange(downlineItems: DownlineTreeviewItem[]) event).

as a sample I modify product.service.ts

getProducts(): TreeviewItem[] {
    const fruitCategory = new TreeviewItem({
      text: 'Fruit', value: 1, children: [
        { text: 'Apple', value: 11, checked: false },
        { text: 'Mango', value: 12, checked: false },
        { text: 'Banana', value: 13, checked: false },
        { text: 'Tomato', value: 14, checked: false },
        { text: 'Orange', value: 15, checked: false }
      ]
    });
    const vegetableCategory = new TreeviewItem({
      text: 'Vegetable', value: 2, children: [
        { text: 'Salad', value: 21, checked: false  },
        { text: 'Potato', value: 22, checked: false },
        { text: 'Spinach', value: 23, checked: false },
        { text: 'Cabbage', value: 24, checked: false },
        { text: 'Carrot', value: 25, checked: false }
      ]
    });
    vegetableCategory.children.push(new TreeviewItem({ text: 'Mushroom', value: 26, checked: false }));
    // vegetableCategory.correctChecked(); // need this to make 'Vegetable' node to change checked value from true to false
    return [vegetableCategory, fruitCategory];
  }

and on product.component.ts I have selected member then set checked to true:

ngOnInit(): void {
    this.items = this.service.getProducts();
    const selectedMembers= [23, 15, 21, 12];
    selectedMembers.forEach((sn) => {
      const node: TreeviewItem = TreeviewHelper.findItemInList(this.items, sn);
      if (node) { node.checked = !node.checked; }
    });
  }

current result
image

expected result
image

Any solution for this or anyone can help?
Thanks.

@dmaf87 dmaf87 changed the title load from data DownlineTreeviewItem selection by order not work load items from data, DownlineTreeviewItem selection by order not work Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant