Primeng: Treetable - Set Selection Tree Node Programmatically Not Working

Created on 3 Jul 2017  路  8Comments  路  Source: primefaces/primeng

I'm submitting a ... (check one with "x")

[ ] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)

  1. Unselect all node from Treetable
  2. Click Set Selection button

https://plnkr.co/edit/2LiR8NNgDmmjWbboVABn?p=preview

Current behavior
Tree Table programmatical Node Selection Not Working

Expected behavior
Tree Table Node Selection Need to set programatically ex. i need to retrieve data from server set set selected node in tree table

Please tell us about your environment:
visual code

  • Angular version: 4.1.3

  • PrimeNG version: 4.0.3
    I am also check your latest release

  • Browser: [Chrome 59.0.3071.115 ]

  • Language: [all | TypeScript X.X | ES6/7 | ES5]

  • Node (for AoT issues): node --version =

Most helpful comment

Hi,
I got a solution and posted here: https://github.com/blogo86/PrimeNGTreeNodePreSelect

All 8 comments

Hi,
Pls let me know that my above query is really a issue or you have solution....
i am in kind of urgent don't mistake me....

The selection must be passed as a variable reference, example:

this.SelectedMenuList = [this.MenuList[0], this.MenuList[0].children[0]];

Yes, as above.

Sorry to piggyback off this. Please let me know if I should open a new issue.
I have tried saving the selected items in a list to localstorage and restoring but it does not show.
I cannot think of the best way to do this. Is there a way to get the index of the selected node when it is selected (many of my nodes are nested)?

i was also facing the same issue. so i have used ng-template and then i have taken input type checkbox and then i have one property "isSelected" in json. and while retrieving values i have looped the json in a recursive way and then compare the values from database and my json then i make the same object found "isSelected" property true.

Sample code:

HTML:




{{node.data.groupName}}

        </p-column>
      </p-treeTable>

JSON:
export class Group {
GroupName: string;
StartDate : string;
isSelected : boolean;
}

Component: i have called this function "setNodeSelecteed()" on the values which i am retrieving from database.

setNodeSelected = function (node, selectGroupName) { // node => this.allGroups
if (node.children && node.children.length > 0) {
for (var i = 0; i < node.children.length; i++) {
this.setNodeSelected(node.children[i], selectGroupName);
}
}
else {
if (node.data.groupName.trim().toLowerCase() === selectGroupName.trim().toLowerCase()) {
node.data.isSelected = true;
}
}
}

Hope this helps you. :)

Found a workaround for preselection of multiple checkboxes in primeng Tree. You can find working example here: https://github.com/jigneshkhatri/primeng-treenode-preselect

Hi,
I got a solution and posted here: https://github.com/blogo86/PrimeNGTreeNodePreSelect

I tried all the mentioned solutions, but still it does not show the checkbox as selected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilling picture lilling  路  3Comments

Faigjaz picture Faigjaz  路  3Comments

gatapia picture gatapia  路  3Comments

garethlewis picture garethlewis  路  3Comments

papiroca-tm picture papiroca-tm  路  3Comments