var keys= [], JsonTree = {}, level=0,maxLevel=1, nodelevels=0,tempnodelevel,mspans=[],nodeNumber=0;
(function ($) {
$.fn.tableJS = function (a,width) {
this.each(function () {
var header = $('<div/>', {class:'header'});
var datadiv = $('<div/>', {id:'tblbdy'});
$(this).append(header);$(this).append(datadiv);
var i=0;
$.each(a[0],function(key,value){
var colLabel = $('<div/>',{class:'colLabel',text:key,'width' :width[i]});
keys.push(key);
header.append(colLabel);
i++;
});
calculateWidthInPx(width,$(this).outerWidth(true))
CreateTree(a);
ConstructTableTree(JsonTree,datadiv,width);
}); // end for each
}; // end of functions
})(jQuery);
// This is autility function that checks if an element exists in the array or not.
function isAvailable(a,b) {
var yes = false;
$.each(a,function(index,ele)
{
if(ele == b)
yes = true;
});
return yes;
}
// This method creates the jsonTree according to the given json Array.
function CreateTree(a) {
$.each(a,function(index,ele) {
var i=0;
var nums=[]
$.each(ele,function(key,value) {
var Nodetype;
if(!isNaN(value))
{
Nodetype=true;
nums.push(i);
}else
Nodetype=false;
ProcessProperty(ele,i,Nodetype,nums)
i++;
}) // for each of json object
}) // for each of json array
}
// This method processes the each and every key of the JSON object and creates the tree accordingly
function ProcessProperty(ele,i,Nodetype,nums) {
var path,skip=0,len=nums.length;
for(var j=0;j<=i;j++)
{
if(j == 0 )
path=ele[keys[j]];
else {
if(Nodetype ===...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.