Convert json to html table
npm install html-tablify```
npm install html-tablify
* Basic usage -
``
var html_tablify = require('html-tablify');
var options = {
data: [{a: 1, b: 2}, {b: 1, a: 2}, {a: 4}]
};
var html_data = html_tablify.tablify(options);
console.log(html_data);`
* Output (pretty) -`
a b
1 2
2 1
4
---
* To specify order of header use 'header' (array) in options -
``
var html_tablify = require('html-tablify');
var options = {
data: [{a: 1, b: 2}, {b: 1, a: 2}, {a: 4, c: 5}],
header: ['a', 'b', 'c']
};
var html_data = html_tablify.tablify(options);
console.log(html_data);`
* Output (pretty) -`
a b c
1 2
2 1
4 5
---
* To map header text to something else use 'header_mapping' in options -
``
var html_tablify = require('html-tablify');
var options = {
data: [{a: 1, b: 2}, {b: 1, a: 2}, {a: 4, c: 5}],
header_mapping: {
a: 'X',
c: 'Z'
}
};
var html_data = html_tablify.tablify(options);
console.log(html_data);`
* Output (pretty) -`
X b Z
1 2
2 1
4 5
---
* To override border(default 1), cellpadding(default 0) and cellspacing(default 0) use 'border', 'cellpadding' and 'cellspacing' in options -
``
var html_tablify = require('html-tablify');
var options = {
data: [{a: 1, b: 2}, {b: 1, a: 2}, {a: 4, c: 5}],
border: 5,
cellspacing: 2,
cellpadding: 3
};
var html_data = html_tablify.tablify(options);
console.log(html_data);`
* Output (pretty) -`
a b c
1 2
2 1
4 5
---
* To apply styling (css) use 'css' in options -
``
var html_tablify = require('html-tablify');
var options = {
data: [{a: 1, b: 2}, {b: 1, a: 2}, {a: 4, c: 5}],
css: 'table {border: 1px solid red}'
};
var html_data = html_tablify.tablify(options);
console.log(html_data);`
* Output (pretty) -`
a b c
1 2
2 1
4 5
---
* To add class to table use 'table_class' in options -
``
var html_tablify = require('html-tablify');
var options = {
data: [{a: 1, b: 2}, {b: 1, a: 2}, {a: 4, c: 5}],
table_class: 'my-table'
};
var html_data = html_tablify.tablify(options);
console.log(html_data);`
* Output (pretty) -``
a b c
1 2
2 1
4 5