Last active
December 12, 2018 00:19
-
-
Save lucidfrontier45/373777ecaec9e1077d73 to your computer and use it in GitHub Desktop.
Convert JSON to a Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert JSON to a Table | |
* require jsontotable [https://github.com/jongha/jquery-jsontotable] | |
* @param {String} id: div id to which the table will be inserted | |
* @param {Array} header_array: array of table headers | |
* @param {Object} data: json object | |
* @return {none} | |
*/ | |
function json2Table(id, header_array, data) { | |
//clear previous one | |
$(id).html(""); | |
//define table properties | |
var table_property = { | |
id : id, | |
header : true, | |
className : 'table table-condensed' | |
}; | |
//generate header | |
header = new Object(); | |
header_array.forEach(function(e, i, a) { | |
header[e] = null; | |
}); | |
$.jsontotable([header].concat(data), table_property); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment