Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "timbles", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "a very simple jQuery plugin for tables, made by the person who literally did not invent tables", | ||
@@ -5,0 +5,0 @@ "main": "timbles", |
@@ -114,5 +114,5 @@ timbles.js | ||
### Generating a table from a JSON file | ||
### Generating a table from a JSON file or an array of row objects | ||
If your data is in a JSON file, add a `<table>` element to your page and then call `timbles` on it. | ||
If your data is in a JSON file or array, add a `<table>` element to your page and then call `timbles` on it. | ||
@@ -128,3 +128,15 @@ <pre><code><table id="example"></table></code></pre> | ||
dataConfig: { | ||
json: 'data.json', // the json file | ||
/** | ||
* There are two types of data that timbles currently accepts: | ||
* - a json filename | ||
* - an array of row objects | ||
* | ||
* by default, timbles will look for a json file name, | ||
* so dataType is not required unless you are giving an array. | ||
* Then you will need to set it to 'array'. | ||
*/ | ||
dataType: 'json', // right now data types can be 'array' or it defaults to 'json' | ||
data: 'data.json', // the json file if dataType is 'json', an array if dataType is 'array' | ||
sorting: true, // if you want columns to be sortable | ||
@@ -154,2 +166,57 @@ columns: [ | ||
Here is an example of an array of row objects: | ||
<pre><code>var localData = [ | ||
{ | ||
name: "dhtmlconf.png", | ||
size: "77 KB", | ||
kind: "PNG Image", | ||
dateAdded: "August 31, 2014, 11:16 PM", | ||
notes: "dhtmlconf logo" | ||
}, | ||
{ | ||
name: "icla.pdf", | ||
size: "26 KB", | ||
kind: "Adobe PDF document", | ||
dateAdded: "August 27, 2014, 12:51 PM", | ||
notes: "Individual Contributor License Agreement" | ||
},{ | ||
name: "Slime Girls - Vacation Wasteland EP.zip", | ||
size: "72.9 MB", | ||
kind: "ZIP archive", | ||
dateAdded: "August 25, 2014, 9:40 PM", | ||
notes: "cool chiptunes from lwlvl" | ||
},{ | ||
name: ".DS_Store", | ||
size: "25 KB", | ||
kind: "Virus", | ||
dateAdded: "February 7, 2014, 10:59 PM", | ||
notes: "lol" | ||
},{ | ||
name: "No_Diggity.mid", | ||
size: "17 KB", | ||
kind: "MIDI file", | ||
dateAdded: "July 3, 2014, 11:34 PM", | ||
notes: "very important karaoke file" | ||
},{ | ||
name: "jorts.svg", | ||
size: "52 KB", | ||
kind: "Plain Text File", | ||
dateAdded: "May 24, 2014, 1:55 PM", | ||
notes: "logo for jort.technology" | ||
},{ | ||
name: "wordpress.sql", | ||
size: "418 KB", | ||
kind: "Plain Text File", | ||
dateAdded: "May 11, 2014, 11:15 PM", | ||
notes: "blog dump" | ||
},{ | ||
name: "foundation-compass-template-master.zip", | ||
size: "6 KB", | ||
kind: "ZIP archive", | ||
dateAdded: "April 21, 2014, 6:59 PM", | ||
notes: "c.s.s. is better that javascript" | ||
} | ||
];</code></pre> | ||
## C.S.S. | ||
@@ -156,0 +223,0 @@ |
@@ -111,15 +111,26 @@ /** | ||
var rows; | ||
$.getJSON( data.dataConfig.json, function(data) { | ||
rows = data; | ||
}).then( function(){ | ||
$.each(rows, function(index, file){ | ||
var $currentRow = $('<tr>'); | ||
$.each(file, function(property, value){ | ||
$currentRow.append('<td class="' + property + '">' + value + '</td>'); | ||
}); | ||
$this.append($currentRow); | ||
if ( data.dataConfig.dataType === 'array' ) { | ||
// no need for ajax call if data is local array | ||
methods.generateRowsFromData.call($this, data.dataConfig.data, $this) | ||
} | ||
else { | ||
// get external json file given | ||
$.getJSON( data.dataConfig.data, function(data) { | ||
console.log('ok'); | ||
methods.generateRowsFromData.call($this, data, $this) | ||
}); | ||
} | ||
}, | ||
generateRowsFromData : function(data, thisTable) { | ||
$.each(data, function(index, file){ | ||
var $currentRow = $('<tr>'); | ||
$.each(file, function(property, value){ | ||
$currentRow.append('<td class="' + property + '">' + value + '</td>'); | ||
}); | ||
thisTable.append($currentRow); | ||
}); | ||
}); | ||
}, | ||
@@ -126,0 +137,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
178188
13
2882
227