Skip to content

Instantly share code, notes, and snippets.

@lucidfrontier45
Last active December 12, 2018 00:19
Show Gist options
  • Save lucidfrontier45/373777ecaec9e1077d73 to your computer and use it in GitHub Desktop.
Save lucidfrontier45/373777ecaec9e1077d73 to your computer and use it in GitHub Desktop.
Convert JSON to a Table
/**
* 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