Giter Site home page Giter Site logo

Comments (6)

stla avatar stla commented on June 15, 2024

Hi @ismirsehregal
Why did you close? Currently there's no way, I think.

from jstreer.

ismirsehregal avatar ismirsehregal commented on June 15, 2024

I wanted to realize a collapsed, but selected tree and thought a selection initially causes the tree to expand. However, this behaviour was caused by a misconfiguration. Actually it does what is expected (see below example).

For the future: If I'd like to try options like this, can this be injected via htmlwidgets::onRender? Otherwise it might make sense to allow the user passing a list of options. What do you think?

library(jsTreeR)

nodes <- list(
  list(
    text = "RootA",
    state = list(loaded = TRUE, opened = FALSE, selected = TRUE, undetermined = FALSE),
    type = "root",
    children = list(
      list(
        text = "ChildA1",
        state = list(loaded = TRUE, opened = TRUE, selected = TRUE, undetermined = FALSE),
        type = "child",
        children = list(list(text = "ChildA12",
                             state = list(loaded = TRUE, opened = TRUE, selected = TRUE, undetermined = FALSE),
                             type = "child"))
      ),
      list(text = "ChildA2",
           state = list(loaded = TRUE, opened = TRUE, selected = TRUE, undetermined = FALSE),
           type = "child")
    )
  ),
  list(
    text = "RootB",
    state = list(loaded = TRUE, opened = FALSE, selected = TRUE, undetermined = FALSE),
    type = "root",
    children = list(
      list(text = "ChildB1",
           state = list(loaded = TRUE, opened = TRUE, selected = TRUE, undetermined = FALSE),
           type = "child"),
      list(text = "ChildB2",
           state = list(loaded = TRUE, opened = TRUE, selected = TRUE, undetermined = FALSE),
           type = "child")
    )
  )
)

types <- list(root = list(icon = FALSE), child = list(icon = FALSE))

jstree(nodes,
       types = types,
       checkboxes = TRUE)

from jstreer.

stla avatar stla commented on June 15, 2024

I think this is not possible with htmlwidgets::onRender, because the options are applied when one initializes the tree.

Indeed, one could allow the user to pass a list of options. Then in the JS one would do:

options.core = {
          data: x.data,
          multiple: x.multiple,
          check_callback: x.checkCallback,
          themes: {
            name: x.theme,
            icons: true,
            dots: true,
            responsive: false
          }
};
$.extend(options.core, x.options);

But this would require that the user knows exactly what he does.

from jstreer.

ismirsehregal avatar ismirsehregal commented on June 15, 2024

I think this would be a good option as long as we keep the current defaults and mark the parameter as "advanced" in the description.

from jstreer.

stla avatar stla commented on June 15, 2024

Hi @ismirsehregal
I added an argument coreOptions. This is on master.

jstree(nodes,
       types = types,
       checkboxes = TRUE,
       coreOptions = list(expand_selected_onload = FALSE)
)

from jstreer.

ismirsehregal avatar ismirsehregal commented on June 15, 2024

Great - thanks Stéphane!

from jstreer.

Related Issues (20)

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.