Skip to content
Martin@MBP edited this page Aug 11, 2013 · 12 revisions

Vision

Trees should support selection of one ore more nodes.

Status

This feature is already implemented (demo).

Yet there are still open questions, so this feature is open for discussion and the API is subject to change.

Please discuss here: https://github.com/mar10/fancytree/issues/12

Requirements

  • Nodes may have a state ´selected´, which is independent from the active state.
  • There must be a visual representation, that makes this distinguishable.
  • The selection state must be easily queried by JS. It must also easily be submitted to the server.
  • Selection must be controllable using events (i.e. return false on beforeSelect).
  • Selection must possible using checkboxes.
    Checkboxes may be hidden globally or by node.
    Checkboxes may be disabled globally or by node.
  • Selection must be possible using the API.
  • We support different modes
    • 1: single
      Only one (or no) node is selected at any time. Selecting another node will deselect the previous.
    • 2: multi
      No, one, or more nodes may be selected at any time.
    • 3: multi-hier
      No, one, or more nodes may be selected at any time.
      In this mode only the selection status of end nodes (i.e. leaves) is relevant!.
      (De)selecting a parent node will (de)select all children.
      If some (but not all) descendants of a node are selected, this node is displayed as 'partly selected'

Diskussion

Resources

Problems

The feature is basically working, but currently there are some main issues and open questions:

  1. Precedence in simple mode
    When the tree source data (or initial Ajax response) contains more than one selected node, should we fix it? If so: how?
  2. Precedence in multi-hier mode
    When the tree source data (or initial Ajax response) contains inconsistent data, should we fix it?
    If so: how?
    Example: a node is marked as selected, but it's children are not. Should we select all children, or deselect the parent?
  3. Lazy trees in multi-hier mode
    When we select a lazy/unloaded node, this means 'select all children'.
    Now we expand the parent, which triggers lazy loading. The response may contain unselected nodes; what now?
  4. Persistence
    This feature must be compatible with persistence (see SpecPersistence)

Proposal

We assume the following use case as most likely:

The server does maintain the tree structure, but not the selection state. For example we have a hierarchical structure of options, but any user will choose it's own selection set.
If the user has finished it's selections, she will submit this data to the server (or the selection set is only used by client-side JavaScript).

This allows the following decisions:

  • When a user expresses a wish by actively selecting a node, this takes precedence.
    So if we select a lazy parent, then expand it, all children are expected to be selected, even if the server sends them unselected.
  • If the server sends selected nodes, we treat this as initial default selection.
  • If this data is inconsistent, we don't repair it!

But we should also make the following - less likely - use case possible:

The tree represents a single data model that is maintained on the server - or the server maintains the tree model by user. Selecting a node will modify the global data. If the tree sends selected nodes, this should take precedence.

Current Specification

TODO (see the demo)

Clone this wiki locally