Code Monkey home page Code Monkey logo

mar10 / fancytree Goto Github PK

View Code? Open in Web Editor NEW
2.8K 2.8K 597.0 13.94 MB

JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading

Home Page: http://wwwendt.de/tech/fancytree/demo

License: Other

CoffeeScript 1.70% JavaScript 64.50% CSS 20.14% HTML 8.26% Python 0.16% Less 5.24%
checkboxes drag-and-drop fancytree javascript jquery-plugin persistence tree treegrid

fancytree's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fancytree's Issues

Get DOM element from tree

Is there a way to get a reference to the DOM element, by accessing FancytreeNode? I have a work-around which involves something like this:
var el = $('li#ft_' + node.key) but this fails sometimes, even though the ID/element exists. It would be nice to just do: var el = $(node.domElement)

Also: Please add a config option to disallow removal of <a> tag. I have a tree with list items such as <a href="#" data-id="..." data-something="bar">..</a>, but Fancytree only collects the href attribute, and removes the <a> tag completely. How could I get access to the data-* attributes?

Partial-selected parents are not selected on init.

Init data:

var operationsData = [{
  "key":"occontrolpanel",
  "title":"Control Panel",
  "folder":true,
  "partial":true,
  "children":[
     {
        "key":"occontrolpanel.home",
        "title":"Home",
        "folder":true,
        "partial":true,
        "children":[
           {
              "key":"occontrolpanel.home.index",
              "title":"View home page",
              "selected":true
           },
           {
              "key":"occontrolpanel.home.stats",
              "title":"View statistics",
              "selected":true
           },
           {
              "key":"occontrolpanel.home.logs",
              "title":"View logs",
              "selected":false
           }
        ]
     }
  ]      
}];

Configuration:

$("#tree").fancytree({
    checkbox: true,
    selectMode: 3,
    activeVisible: true,
    clickFolderMode: 3,
    source: operationsData
});

How it looks:
tree-nopartial
How it should look:
tree-partial

Allow to display only a subset of branches

Currently the filter extension dimms or hides nodes that do not match a certain pattern or condition,
If we want to display only a certain node and all its descendants, we would have to call tree.applyFilter(filter) with a callback that returns true for that node and all its children.

This can be simplified by a new method tree.filterBranches(filter), which could be implemented more efficiently.

Maybe we should also rename tree.applyFilter(filter) to tree.filterNodes(filter)

Event to indicate tree is done processing?

The issue is that the beforeSelect, and Select events will fire with each node selection. Picture clicking on the parent of three children, it will cause three selection events to fire. I need a way to identify when the entire process is complete. Essentially a PostOperations event indicating all previous events are complete.

Many examples use .visit(), which raises events at a node level. This causes issues in cases where you only want to fire a chained procedure after the .visit() is complete.

So far the best candidate is the focus event since it only fires once after the select event. However, I was forced to modify the source code and comment out the check that prevents the focus event from firing if it is already in focus.

         nodeSetFocus: function(ctx, flag) {}
               if(tree.focusNode === node && flag){
                    node.debug("nodeSetFocus(" + flag + "): nothing to do");
                  return;

I don't like modifying the source code. Am I missing another event that fires after the Select event finishes?

Lazy load for activateKey

When calling activateKey for a node that has not yet been loaded lazily, nothing happens as getNodeByKey doesn't find a node. Could a new feature be added that in this case Fancytree will make a lazy load operation to fetch the missing tree branch? If the convention will be to return a node source with all ancestor nodes and their siblings, the missing branch could added to the tree.

Filter hidden function on fancytree table not working

When you add the filter extension to a fancytree with table extension, the filtered elements are not correctly hidden.
You can change the jquery.fencytree.filter.js adding:

if(opts.filter.mode === "hide"){
var visible = !!(node.match || node.subMatch);
node.debug(node.title + ": visible=" + visible);
$(node.li).toggle(visible);
if ($(node.tr)!=null) {
$(node.tr).toggle(visible);
}
}

to fix the problem.

Abstract key, title and children paths

Hi,

it could be useful for people that can't change what it comes from the server and want to avoid a extra step to create the data array.

I could try to do that if there is any interest.

e.g.

{ 
  keyPath: "id",
  titlePath: "label",
  childrenPath: "nodes"
}

Change namespace

e.g.
ryrych/rcarousel#16
or

When you define a widget with the $.widget("namespace.widgetname") syntax, the widget factory instantiates the widget "class" inside $[ namespace ]. All jQuery UI widgets exist in the $.ui namespace, which is reserved for official widgets, so make sure you change this to something unique. Namespaces are used internally for organizational purposes; they do not allow you to create multiple widgets with the same name.

expand and hide all for lazy loaded tree

Hello, for dyna tree there was some indication that expand and collapse all are possible for lazy loaded tree using onLazyRead. This seems to be missing in the new fancytree. Is there some way to get this function back up?

Thank you

Does lazy loading with persistence still in effect with fancytree?

In dynatree, there was some example that uses initAjax and postInit to call data from the server.

First of all, is this possible with just json calls? ( I am using ruby so my data is passed around in json)

since initAjax was changed to source, my source is a list of roots so how would I auto reactivate the children nodes? Is there some new functions available for this option? Any hints would be appreciated!

Fancytree Treetable function disable file show?

How would you hide the file and folder images from showing in the treetable? Also, when I try to show only the checkboxes and names only, I cannot only have 1 header and and one row... I need to have a secondary header and row to display one column which I find weird.

Request: Reinstate ".d" property parsing as dynatree used to

dynatree.js had the following in the "appendAjax" function:

else if (data && data.hasOwnProperty("d")) {
data = (typeof data.d) == "string" ? $.parseJSON(data.d) : data.d;
}

It would be extremely useful to have this back in fancytree please to cater for asp.net webmethod json function returns.

Scrolling defect

Hello,

I got strange error message. When I scroll vertical scroll bar of fancytree widget I got error message "ERROR?: helper requested but sourceNode not found."
In source code it says:
jquery.fancytree-all.js
line: 3877
if(!sourceNode){ // issue 211
// TODO: remove this hint, when we understand when it happens
return "

ERROR?: helper requested but sourceNode not found
";
}

Please, check attached file.

Thanks,
Yernar
fancytree defect

unselectable no longer works

In Dynatree there was an "unselectable" property that prevented selection:

{"key":"4","title":"Sub-item 4.4 (unselectable)", "unselectable":true }

The demo page shows an example that allows these nodes to be clicked:
http://wwwendt.de/tech/fancytree/demo/

10

I modified the selectable demo to illustrate this more cleanly. In the demo below clicking the parent folder in selectMode 3 resulted in the unselectable node being selected.

<script type="text/javascript"> var treeData = [ {title: "My Folder with Unselectable inside", key: "id4", expand: true, children: [ {title: "Sub-item 4.3 empty"}, {title: "Sub-item 4.4 (unselectable)", unselectable: true }, {title: "Sub-item 4.5 empty", unselectable: true } ] }, {title: "item (unselectable)", unselectable: true } ]; $(function(){ // --- Initialize sample trees $("#tree1").fancytree({ // extensions: ["select"], checkbox: true, selectMode: 1, source: treeData, activate: function(e, data) { $("#echoActive1").text(data.node.title); }, select: function(e, data) { // Display list of selected nodes var s = data.tree.getSelectedNodes().join(", "); $("#echoSelection1").text(s); }, dblclick: function(e, data) { data.node.toggleSelected(); }, keydown: function(e, data) { if( e.which === 32 ) { data.node.toggleSelected(); return false; } } }); $("#tree2").fancytree({ // extensions: ["select"], checkbox: true, selectMode: 2, source: treeData, select: function(e, data) { // Display list of selected nodes var selNodes = data.tree.getSelectedNodes(); // convert to title/key array var selKeys = $.map(selNodes, function(node){ return "[" + node.key + "]: '" + node.title + "'"; }); $("#echoSelection2").text(selKeys.join(", ")); }, click: function(e, data) { // We should not toggle, if target was "checkbox", because this // would result in double-toggle (i.e. no toggle) if( $.ui.fancytree.getEventTargetType(e) == "title" ){ data.node.toggleSelected(); } }, keydown: function(e, data) { if( e.which === 32 ) { data.node.toggleSelected(); return false; } }, // The following options are only required, if we have more than one tree on one page: cookieId: "fancytree-Cb2", idPrefix: "fancytree-Cb2-" }); $("#tree3").fancytree({ // extensions: ["select"], checkbox: true, selectMode: 3, source: treeData, select: function(e, data) { // Get a list of all selected nodes, and convert to a key array: var selKeys = $.map(data.tree.getSelectedNodes(), function(node){ return node.key; }); $("#echoSelection3").text(selKeys.join(", ")); // Get a list of all selected TOP nodes var selRootNodes = data.tree.getSelectedNodes(true); // ... and convert to a key array: var selRootKeys = $.map(selRootNodes, function(node){ return node.key; }); $("#echoSelectionRootKeys3").text(selRootKeys.join(", ")); $("#echoSelectionRoots3").text(selRootNodes.join(", ")); }, dblclick: function(e, data) { data.node.toggleSelected(); }, keydown: function(e, data) { if( e.which === 32 ) { data.node.toggleSelected(); return false; } }, // The following options are only required, if we have more than one tree on one page: // initId: "treeData", cookieId: "fancytree-Cb3", idPrefix: "fancytree-Cb3-" }); $("#tree4").fancytree({ // extensions: ["select"], checkbox: false, selectMode: 2, source: treeData, beforeSelect: function(e, data) { if( data.node.folder ){ return false; } }, select: function(e, data) { // Display list of selected nodes var selNodes = data.tree.getSelectedNodes(); // convert to title/key array var selKeys = $.map(selNodes, function(node){ return "[" + node.key + "]: '" + node.title + "'"; }); $("#echoSelection4").text(selKeys.join(", ")); }, click: function(e, data) { if( ! data.node.folder ){ data.node.toggleSelected(); } }, dblclick: function(e, data) { data.node.toggleExpanded(); }, keydown: function(e, data) { if( e.which === 32 ) { data.node.toggleSelected(); return false; } }, // The following options are only required, if we have more than one tree on one page: // initId: "treeData", cookieId: "fancytree-Cb4", idPrefix: "fancytree-Cb4-" }); $("#btnToggleSelect").click(function(){ $("#tree2").fancytree("getRootNode").visit(function(node){ node.toggleSelected(); }); return false; }); $("#btnDeselectAll").click(function(){ $("#tree2").fancytree("getTree").visit(function(node){ node.setSelected(false); }); return false; }); $("#btnSelectAll").click(function(){ $("#tree2").fancytree("getTree").visit(function(node){ node.setSelected(true); }); return false; }); }); </script>

Example: Selection and checkbox

<!-- Tree #1 -->

<p class="description">
    This tree has <b>checkoxes and selectMode 1 (single-selection)</b> enabled.<br>
    A double-click handler selects a <i>document</i> node (not folders).<br>
    A keydown handler selects on [space].<br>
    The <code>checkbox</code> icons are replaced by radio buttons by adding
    the 'fancytree-radio' class to the container.<br>
    Note: the initialization data contains multiple selected nodes. This is
    considered bad input data and <b>not</b> fixed automatically (only on
    the first click).
</p>
<div>
    <label for="skinswitcher">Skin:</label> <select id="skinswitcher"></select>
</div>
<div id="tree1" class="fancytree-radio">
</div>
<div>Active node: <span id="echoActive1">-</span></div>
<div>Selection: <span id="echoSelection1">-</span></div>


<!-- Tree #2 -->

<p class="description">
    This tree has <b>selectMode 2 (multi-selection)</b> enabled.<br>
    A single-click handler selects the node.<br>
    A keydown handler selects on [space].
</p>
<p>
    <a href="#" id="btnSelectAll">Select all</a> -
    <a href="#" id="btnDeselectAll">Deselect all</a> -
    <a href="#" id="btnToggleSelect">Toggle select</a>
</p>
<div id="tree2"></div>
<div>Selected keys: <span id="echoSelection2">-</span></div>


<!-- Tree #3 -->

<p class="description">
    This tree has <b>checkoxes and selectMode 3 (hierarchical multi-selection)</b> enabled.<br>
    A double-click handler selects the node.<br>
    A keydown handler selects on [space].
</p>
<div id="tree3"></div>
<div>Selected keys: <span id="echoSelection3">-</span></div>
<div>Selected root keys: <span id="echoSelectionRootKeys3">-</span></div>
<div>Selected root nodes: <span id="echoSelectionRoots3">-</span></div>


<!-- Tree #4 -->

<p class="description">
    This tree has selectMode 2 (multi-selection) enabled, but <b>no checkboxes</b>.<br>
    A single-click handler selects the node.<br>
    A keydown handler selects on [space].<br>
    A double-click handler expands documents.<br>
    A onQuerySelect handler prevents selection of folders.
</p>
<div id="tree4"></div>
<div>Selected keys: <span id="echoSelection4">-</span></div>


<!-- Start_Exclude: This block is not part of the sample code -->
<hr>
<p class="sample-links  no_code">
    <a class="hideInsideFS" href="https://github.com/mar10/fancytree">jquery.fancytree.js project home</a>
    <a class="hideOutsideFS" href="#">Link to this page</a>
    <a class="hideInsideFS" href="index.html">Example Browser</a>
    <a href="#" id="codeExample">View source code</a>
</p>
<pre id="sourceCode" class="prettyprint" style="display:none"></pre>
<!-- End_Exclude -->

Focusing on first tree node when bringing tree into focus with a mouse

When clicking on a node (not first one) of an unfocused tree with a mouse the first tree node gets focused, and the node being clicked gets active status. Expected only the node being clicked to receive focus/active status.

Under debugger it seems to work as intended. Seems to be some timing/racing problem.

firefox 20
fancytree 2.0.0pre, commit bee0c40
extensions: themeroller

Persistence for lazy trees

Could you be able to fix the lazy load part of the persistence example to show its children? right now it is toggled without showing any children. I tried out the load key but can't get it to work...

dnd extension + up to data jquery and jquery ui

Hi there!

Any chance we can get a working dnd extension with more recent jquery and jquery ui libs? It doesn't work with jquery 2.0.0 and jquery ui 1.10.3.

Thanks,
cheers singultus

PS: really great tree library!

Filter Using fancytree table

During the usage of fancytree table with fancy tree filter, the filter style is not correctly apply (because in the fancytree css style look for a span element).

To fix the problem you can just add:

/* filter for table */
.fancytree-ext-filter tr.fancytree-node .fancytree-title {
color: silver;
font-weight: lighter;
}
.fancytree-ext-filter tr.fancytree-node.fancytree-submatch .fancytree-title {
color: black;
font-weight: normal;
}
.fancytree-ext-filter tr.fancytree-node.fancytree-match .fancytree-title {
color: black;
font-weight: bold;
}

to the ui.fancytree.css

Clicking Expand Causes Intermittent Browser Hang for Firefox

Doing the same operation, ie clicking the expand icon of a folder, results in different browser responses. Sometimes it processes the Javascript and then shows the completely rendered nodes immediately when the Javascript finishes.

Other times, the exact same: data, expander, browser, and code, can cause a browser hang (presumably a reflow/repaint).

The confusing part is that this comes and goes with no real pattern. Hitting ctrl-F4 on the same tab and doing the same operations results in two different outcomes.

When the browser is frozen (use the 10K node sample), it can stay frozen for longer than 10 seconds. Two indicators make the browser hang easy to spot:

  1. The rightmost scrollbar does not re-size to show the new length of the page. It does after the 10 second hang is over.
  2. Sometimes the node level icons will not render, so just the text of the nodes is visible. Again, goes away after the hang finishes.

Example of problem (when scroll has not rendered):
browserhang reflow or rerender v1

Example of after the hang is done. Ie what the page should look like:
browserhang reflow or rerender - completed- v2

Browsers Un-Affected:
IE 9-10
Chrome

Browsers Affected:
Firefox

Option for Faster Node Rendering & Creation

Allow the option to create nodes faster. Creating an issue to track the various ways to speed up the rendering of 10,000 node children within a single folder.

I created a sample and will upload it. Essentially, it adds an option "renderNodeEvents" that the user can set to FALSE. By disabling these two event calls the speed increases dramatically.

My proposed code changes have the following benchmark scores in Firefox:

Original: 5091 ms
Proposed: 1650 ms
i.e. 68% faster

Before closing this issue, I would like to have a discussion about how the nodeRender: function() works. I originally tried to improve the generation by modifying this method. I feel like there is a way to use Document Fragments to speedup the generation. I wasn't 100% sure that the current method adds the entire tree to the DOM in one addition (ie if the deep=true). It seems like it might add each completed LI to the DOM (which could happen several times).

Three references:
http://ejohn.org/blog/dom-documentfragments/
https://developers.google.com/speed/articles/javascript-dom
http://jsperf.com/documentfragmentui

i18n

Please, move all strings visible to users to an object in initialization options, so others could translate them to their language if they want to.

REQUEST: Inverse hierarchical select mode

Hi I use a tree to assign categories to e.g. books. Now if I have categories like:
Science
-- Botany
-- Chemistry

I like to have the parent selected as soon as I select one of the children as every botany book is a science book but not vice versa. Not every science book is a botany and chemistry book.

Activating a FancyTree node causes Backspace to stop working in input fields on IE8

This issue occurs with the newest FancyTree version (as well as older ones I've tried) and does not seem to depend on the jQuery version.

Steps to reproduce

  1. Open this JS Bin link in IE8 (here's a Gist if you don't like JS Bin). Note: This issue does not occur when using a newer IE in IE8 mode โ€” you have to use real IE8.
  2. Type something in the text field and try pressing Backspace. It should work.
  3. Click any of the FancyTree nodes (Node 1, for instance) to activate it.
  4. Try deleting some of the text in the text field by pressing Backspace. It doesn't work.

Something that may help point you in the right direction: I tried commenting out l. 3034 of jquery.fancytree.js and that seems to fix the backspace issue without preventing the node from being activated, but it probably does something else important I didn't get to yet.

The console is of no help, unfortunately, since IE8 doesn't have one.

Attempt to activateKey after ajax load does not work

I'm loading my tree via ajax json call (5K nodes)
If I attempt to activateKey in JS right after creating fancytree call, the nodes have not finished loading yet and activateKey fails (I log the count() before the activateKey call).
If I attempt to activateKey in a setTimeout, still fails. I've tried 1-5 sec to no avail.

If I make same exact call in Chrome Console, the node activates perfectly.
So I'm really not sure what is going on.

Ideally, it would be nice if there was an event handler on the tree object once everything had finished that you can safely call a node activation.

Thanks for your time!

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.