hColumns is a jQuery plugin that looks like Mac OS X Finder's column view for the hierarchical data.
<link rel="stylesheet" href="css/reset.css" type="text/css"> <link rel="stylesheet" href="css/hcolumns.css" type="text/css">
<div id="columns">div>
<script src="js/jquery-1.9.1.min.js">script> <script src="js/jquery.hcolumns.min.js">script> <script> $(document).ready(function() { $("#columns").hColumns({ nodeSource: function(node_id, callback) { } }); }); }); }); script>
Node source is a Javascript function that provide hColumns children nodes. To write one is simple and quick.
How to write a Node SourceNode Source is a function that receive two parameters: node_id, callback
And return an array contains nodes, each node is a object *at least* contains: id, label, type
A simple one might be:
function(node_id, callback) { // callback is a function that receive two parameter // callback(error, array of nodes); // if inital load if(node_id === null) { return callback(null, [ { id: 1, label: "folder", type: "folder" }, { id: 2, label: "empty", type: "folder" }, { id: 3, label: "Google", type: "link", url: "http://www.google.com" } ]); } if(node_id === 1) { return callback(null, [ { id: 11, label: "Google in a folder", type: "link", url: "http://www.google.com" } ]); } // even empty nodes, you need to return empty array [] if(node_id === 2) { return callback(null, []); } }
Or it can use backend resource, like PHP
Node Sourcefunction(node_id, callback) { $.ajax("resource.php", { node_id: node_id }).done(function(data) { return callback(null, data); }).fail(function() { return callback("AJAX error"); }); }resource.php
// example for hColumns
// by bu <>
$node_id = filter_input(INPUT_GET, "node_id", FILTER_SANITIZE_NUMBER_INT);
if( $node_id == NULL ) {
echo json_encode(array(
0 => array( "id" => 1, "label" => "from PHP", "type" => "folder")
));
}
if( $node_id == 1 ) {
echo json_encode(array());
}
Well, this plugin was not shipped a default data source, for two reasons:
var defaultConfig = { // source for node retrieve nodeSource: function() { return window.alert("dummy source, you need to create a node source"); }, // short message for empty node noContentString: "There is no node here", // custom type for the list customNodeTypeIndicator: {}, customNodeTypeHandler: {} };
label text string, no node string, custom type
Description for customNodeType
Please visit , and feel free to create an issue for your problems.
Buwei Chiu (a.k.a. bu) -
BSD