jigneshkhatri / primeng-treenode-preselect Goto Github PK
View Code? Open in Web Editor NEWWorkaround for pre-selection of TreeNodes in primeng tree (multiple checkbox selection).
Workaround for pre-selection of TreeNodes in primeng tree (multiple checkbox selection).
This is complete json data which i submitted. how i need to get only preselect json data after page refresh/update the component.
Example :
[
{
"label": "Documents",
"data": "Documents Folder",
"expandedIcon": "fa fa-folder-open",
"collapsedIcon": "fa fa-folder",
"children": [{
"label": "Work",
"data": "Work Folder",
"expandedIcon": "fa fa-folder-open",
"collapsedIcon": "fa fa-folder",
"children": [{"label": "Expenses.doc", "icon": "fa fa-file-word-o", "data": "Expenses Document"}, {"label": "Resume.doc", "icon": "fa fa-file-word-o", "data": "Resume Document"}]
},
{
"label": "Home",
"data": "Home Folder",
"expandedIcon": "fa fa-folder-open",
"collapsedIcon": "fa fa-folder",
"children": [{"label": "Invoices.txt", "icon": "fa fa-file-word-o", "data": "Invoices for this month"}]
}]
},
{
"label": "Pictures",
"data": "Pictures Folder",
"expandedIcon": "fa fa-folder-open",
"collapsedIcon": "fa fa-folder",
"children": [
{"label": "barcelona.jpg", "icon": "fa fa-file-image-o", "data": "Barcelona Photo"},
{"label": "logo.jpg", "icon": "fa fa-file-image-o", "data": "PrimeFaces Logo"},
{"label": "primeui.png", "icon": "fa fa-file-image-o", "data": "PrimeUI Logo"}]
},
{
"label": "Movies",
"data": "Movies Folder",
"expandedIcon": "fa fa-folder-open",
"collapsedIcon": "fa fa-folder",
"children": [{
"label": "Al Pacino",
"data": "Pacino Movies",
"children": [{"label": "Scarface", "icon": "fa fa-file-video-o", "data": "Scarface Movie"}, {"label": "Serpico", "icon": "fa fa-file-video-o", "data": "Serpico Movie"}]
},
{
"label": "Robert De Niro",
"data": "De Niro Movies",
"children": [{"label": "Goodfellas", "icon": "fa fa-file-video-o", "data": "Goodfellas Movie"}, {"label": "Untouchables", "icon": "fa fa-file-video-o", "data": "Untouchables Movie"}]
}]
}
]
Here is the correct code-
checkNode(nodes: TreeNode[], str: string[]) {
for (let i = 0; i < nodes.length; i++) {
if (!nodes[i].leaf) {
for (let j = 0; j < nodes[i].children.length; j++) {
if (str.includes(nodes[i].children[j].data)) {
if (!this.selectedFiles.includes(nodes[i].children[j])) {
this.selectedFiles.push(nodes[i].children[j]);
}
}
}
} else {
if (str.includes(nodes[i].data)) {
if (!this.selectedFiles.includes(nodes[i])) {
this.selectedFiles.push(nodes[i]);
}
}
}
if (nodes[i].leaf) {
continue;
} else {
this.checkNode(nodes[i].children, str);
const count = nodes[i].children.length;
let c = 0;
for (let j = 0; j < nodes[i].children.length; j++) {
if (this.selectedFiles.includes(nodes[i].children[j])) {
c++;
}
if (nodes[i].children[j].partialSelected) {
nodes[i].partialSelected = true;
}
}
if (c === 0) { } else if (c === count) {
nodes[i].partialSelected = false;
if (!this.selectedFiles.includes(nodes[i])) {
this.selectedFiles.push(nodes[i]);
console.log(this.selectedFiles);
}
} else {
nodes[i].partialSelected = true;
}
}
}
}
To utilize this, don't we need to totally replace the "p-tree" component as well, being it imports TreeNode? I'm figuring we would need to replace the import in "p-tree" with these custom files.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.