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

treetables

v1.2.1

Published

jquery plugin extending jquery-datatables to support tree data

Downloads

84

Readme

TreeTables plug-in for jQuery

Build Status codecov.io

TreeTables is a jQuery plugin that enhances the functionality of the popular DataTables plugin.

DataTables does not support tree data by default, so this plugin adds that support.

Please note that TreeTables does not support server-side processing.

Screenshot of plugin in use

Installation options

  1. Download: First download the base DataTables scripts here: https://datatables.net/download/ Then also download this repo and include the following scripts on your page:

    <script type="text/javascript" src="DataTables/datatables.min.js"></script>
    <script type="text/javascript" src="treeTable.js"></script>

    And the following css in your document head:

    <link rel="stylesheet" type="text/css" href="DataTables/datatables.min.css"/>
    <link rel="stylesheet" type="text/css" href="tree-table.css"/>

    See examples for styling with Bootstrap

  2. npm: npm install treetables

Basic Usage

 const organisationData = [
            {tt_key: 1, tt_parent: 0, name: "CEO"},
            {tt_key: 2, tt_parent: 1, name: "CTO"},
            {tt_key: 3, tt_parent: 2, name: "developer"},
            {tt_key: 4, tt_parent: 1, name: "CFO"}
        ];

        $('#my-table').treeTable({
            "data": myData,
            "columns": [
                {
                    "data": "name"
                }
            ]
        });

Data provided to the table must include the following fields:

  • tt_key: number - a unique row identifier. Must be 1-indexed.
  • tt_parent: number - the key of this row's parent row

Options

TreeTable options are most DataTable options plus:

  • collapsed: bool - whether to start with all child rows collapsed
        $('#my-table').treeTable({
            "data": myData,
            "collapsed": true,
            "columns": [
                {
                    "data": "name"
                }
            ]
        });

Please note that the TreeTable plugin adds a left-hand column to the table. This means that user provided columns are 1-indexed instead of 0-indexed.

E.g., this table will be initially sorted by name:

        $('#my-table').treeTable({
            "data": myData,
            "columns": [
                {
                    "data": "name"
                },
                {
                    "data": "salary"
                }
            ],
            "order": [[ 1, 'asc' ]]
        });

API

The DataTables API will be attached to the table element in the usual way, accessible by $('#my-table').DataTable()

Please note that as with the options, columns are 1-indexed. E.g. to re-sort the above table by salary:

 $('#my-table').DataTable()
               .order([ 2, 'asc' ])
               .draw();

Additionally the TreeTable plugin exposes API methods for collapsing and exanding rows via $('#myTable').data('treeTable')

To expand all rows:

$('#myTable').data('treeTable')
                .expandAllRows()
                .redraw();

To collapse all rows:

$('#myTable').data('treeTable')
                .collapseAllRows()
                .redraw();

Ajax data sources

TreeTables has minimal support for ajax data sources. The ajax option can be used as per the DataTables documentation, but it does not support server-side processing, and it does not support the ajax related API methods: ajax.json(), ajax.reload(), ajax.url()

Examples

See examples/README.md

Thanks

This plugin was inspired by a jsfiddle posted by a user called Mytko in the datatables forum: https://datatables.net/forums/discussion/25045/treetable-in-datatables