Code Monkey home page Code Monkey logo

primeng-treenode-preselect's Introduction

primeng-treenode-preselect

Workaround for pre-selection of TreeNodes in primeng tree (multiple checkbox selection).

primeng-treenode-preselect's People

Contributors

jigneshkhatri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

primeng-treenode-preselect's Issues

p-tree preselect json data

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"}]
}]
}
]

How do we use this?

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!

checkNode function doesn't correctly create selection variable.

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;
        }
      }
    }
  }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.