0.3.0 • Published 10 years ago

uxrocket.treelist v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

UX Rocket Treelist

UX Rocket Treelist component provides an expandable/collapsible row systems for the tables. Semantically, all rows are in the same level but visually they are bound with id and parent/child relation.

Installation

According to your usage, you can use directly dist version or, add lib to your project. First you need to checkout the packages from either npm or bower

npm

npm install uxrocket.treelist

or bower

bower install uxrocket.treelist

For Development

If you want to add your project source, import JS and Sass files in lib folder to your project. For the Sass files, use _uxrocket-treelist.scss partial file instead of uxrocket.treelist.scss

// styles.scss
// Plugin styles
@import "<path-to-treelist>/lib/_uxrocket-treelist";

// Your project styles
// app.js
// If you use Grunt or Gulp, add <path-to-treelist>/lib/uxrocket.treelist.js to your config
// For Codekit or similar tools
// @codekit-append '<path-to-treelist>/lib/uxrocket.treelist.js'

For Direct Usage

In your HTML after jQuery add uxrocket.treelist.min.js and add styles to your head

<head>
    ...
    <link rel="stylesheet" href="<path-to-treelist>/dist/uxrocket.treelist.min.css" />
    <script src="<path-to-jquery>/jquery.js"></script>
    <script src="<path-to-treelist>/dist/uxrocket.treelist.min.js"></script>
    ...
</head>

Usage

Sample HTML structure as follows,

<table class="treelist" data-on-destroy="console.log('removed')">
    <thead>
        <tr>
            <th>Name</th>
            <th>Version</th>
            <th>Type</th>
        </tr>
    </thead>
    <tbody>
        <tr data-uxrtl-id="1" data-on-expand="console.log('expanded')">
            <td class="uxr-treelist-toggle">UX Rocket Treelist</td>
            <td>0.1.0</td>
            <td>Plugin</td>
        </tr>
        <tr data-uxrtl-id="2" data-uxrtl-parent="1">
            <td>jQuery</td>
            <td>Latest</td>
            <td>Dependency</td>
        </tr>
        <tr data-uxrtl-id="3" data-active="true">
            <td>UX Rocket Autocomplete</td>
            <td>2.0.2</td>
            <td>Plugin</td>
        </tr>
        <tr data-uxrtl-id="4" data-uxrtl-parent="3">
            <td>jQuery</td>
            <td>Latest</td>
            <td>Dependency</td>
        </tr>
        <tr data-uxrtl-id="5">
            <td>UX Rocket Modal</td>
            <td>0.8.0</td>
            <td>Plugin</td>
        </tr>
    </tbody>
</table>

After preparing above HTML, bind plugin to your table

$(function(){
    // standard
    $('.treelist').treelist();
});

By default, treelist does not have a configurable options. You can define, onReady and onRemove callbacks for related events. However, you can add options via data attributes to nodes.

Options

PropertyDefaultDescription
headernullCustom class names for parent rows
contentnullCustom class names for child rows
togglenullCustom class names for toggle
Data AttributesDescription
data-on-expandFunction/method called after parent row expaned. Applies to parent row
data-on-collapseFunction/method called after parent row collapsed. Applies to parent row
data-activeIf set true parent row and its sub rows will be expanded on load.
data-uxrtl-idGeneric ID attribute for rows. Only required if row is a parent
data-uxrtl-parentParent ID for the child rows. Required for obtaining parent/child relation
data-on-readyFunction called after plugin binded to table. Applies to table itself
data-on-removeFunction called when plugin destroyed. Applies to table itself
Callback 
onReadyFunction called after plugin binded to table. Applies to table itself
onRemoveFunction called when plugin destroyed. Applies to table itself
Events 
uxrreadyTriggered when plugin bind to table
uxrexpandedTriggered when a row expanded
uxrcollapsedTriggered when a row collapsed
uxrleafcollapsedTriggered when a child row, is also a parent row, collapsed
uxrremoveTriggered when plugin destroyed/removed from table

Public Methods

MethodDescription
$(selector).treelist(options)Binds plugin to a table
$.uxrtreelistPlugin name
$.uxrtreelist.versionDisplays the plugin version
$.uxrtreelist.settingsDisplays the default plugin settings