npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jquery-bigtree

v1.0.8

Published

High performance jQuery plugin for rendering hierarchical data based on nested set model (pre-order tree)

Downloads

3

Readme

#Bigtree

High performance hierarchical data rendering based on nested set model (pre-order tree).

##Features

  • Large dataset
  • Virtual scrolling
  • Movable (dragdrop) nodes
  • Editable nodes
  • Keyboard navigation
  • User plugins

##Dependencies

Bigtree is jQuery plugin that relies on some libraries:

##Install

npm install jquery-bigtree

##Demo

Demo

##Usage

$('element').bigtree();

// with options
$('element').bigtree({
    markup: '<div></div>'
});

Hierarchical structure illustration:

tree

Then, we transform the data into json:

var data = [
    {id: 1, text: 'ROOT', left: 1, right: 10, level: 0, leaf: 0, expand: 1, path: '1'},
    {id: 2, text: 'A',    left: 2, right:  7, level: 1, leaf: 0, expand: 1, path: '1/2'},
    {id: 3, text: 'B',    left: 3, right:  4, level: 2, leaf: 1, expand: 1, path: '1/2/3'},
    {id: 4, text: 'C',    left: 5, right:  6, level: 2, leaf: 1, expand: 1, path: '1/2/4'},
    {id: 5, text: 'D',    left: 8, right:  9, level: 1, leaf: 1, expand: 1, path: '1/5'}
];

Then, we load into plugin:

$('element').bigtree('load', data, true);

##Options

####- fields Type: Object Default: {}

Node field mapping to tranform real data field to node field, so plugin can works with user data structure (model).

fields: {
    id:     'id',
    text:   'text',
    left:   'left',
    right:  'right',
    level:  'level',
    leaf:   'leaf',
    path:   'path',
    expand: 'expand'
}

####- itemSize Type: Number Default: 32

Height for each rendered node.

####- stepSize Type: Number Default: 25

Padding size for each level.

####- delay Type: Number Default: 30

Scrolling delay, used for change scrolling size.

####- buffer Type: Number Default: 0

Leading and trailing rendered nodes from edges.

####- markup Type: String Default: <div></div>

Recommended markup used to render each node, support jsrender templtating tags.

<div class="bt-node bt-hbox" data-id="{{:id}}">
    <div class="bt-node-body bt-flex bt-hbox">
        <div class="bt-drag"></div>
        <div class="bt-plugin head"></div>
        <div class="bt-text bt-flex bt-hbox">{{:text}}</div>
        <div class="bt-plugin tail"></div>
    </div>
</div>

##Methods

####- load() Arguments: (Array data[, Boolean render = false]) Return: void

Used for loading data into plugin.

var data = [/* YOUR DATA HERE */];

$('element', data, true);

We can also loading data from paginated ajax request, for example:

var start = 0, limit = 100;

function load(start, limit) {
    $.ajax({
        url: 'tree.php',
        type: 'post',
        dataType: 'json',
        data: {
            start: start,
            limit: limit
        }
    }).done(function(response){
        // for example, we have following response
        // {data: [], total: 10000}

        $('element').bigtree('load', response.data);
        
        if ( ! $('element').bigtree('scrollable')) {
            $('element').bigtree('render');
        }

        start += limit;

        if ( start < response.total ) {
            // continue load
            load(start, limit);
        }
    });
}

// run first time
load(start, limit);

##Events

####- init.bt Arguments: (Event e)

Fired after plugin initialized.

$('element').on('init.bt', function(e){
    $('element').children().html('Loading...'); 
});

####- beforerender.bt Arguments: (Event e, Array data)

Fired before nodes rendered.

####- render.bt Arguments: (Event e, Array data, Array nodes)

Fired after nodes rendered.

####- expand.bt Arguments: (Event e, Object data)

Fired after node expanded.

$('element').on('expand.bt', function(e, data){
    $.ajax({
        url: 'update.php',
        data: {
            id: data.id,
            expand: data.expand
        }
    });
});

####- collapse.bt Arguments: (Event e, Object data)

Fired after node collapsed.

Plugin

You can write your own plugin for handle specific data (node).


var TrashPlugin = (function(){
   
    var Plugin = function() {
        /**
         * Template plugin
         */
        this.template = '<a href="#">' + 
                            '<i class="fa fa-trash-o"></i>{{:this.caption}}' + 
                        '</a>';

        /**
         * Plugin placement
         *
         * value: tail, head
         */
        this.place = 'tail';

        this.init();
    };

    Plugin.prototype = {

        update: function() {
            this.caption = 'Delete';
        },

        onInit: function (tree, data) {
            this.tree = tree;
            this.data = data;
        },

        onRender: function() {
            var tree = this.tree, data = this.data;

            this.element.on('click', function(e){

                if (confirm('Delete selected data?')) {
                    tree.remove(data);
                }

            });
        },

        onSuspend: function() {

        },

        destroy: function() {

        }
    };

    return Plugin;
});

Registering plugins:


$('element').bigtree({
    markup: '...',
    plugins: [
        new TrashPlugin({id: 'trash'})
    ]
});