Skip to content

Add custom parser and more features #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions Example/Example parse function.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>JSON-to-Table parser example</title>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:300|Open+Sans+Condensed:300|Open+Sans:300"
rel="stylesheet">
<style>
body {
font-family: 'Josefin Sans', sans-serif;
}

h1 {
font-size: 40px;
color: #08090d;
text-align: center;
}

h1 span {
font-size: 25px;
color: #477dd7;
}

h2 {
font-family: "Open Sans Condensed", sans-serif;
font-size: 18px;
}

.margin-bottom {
margin-bottom: 50px;
}
</style>
</head>
<body>
<h1>JSON Data To HTML Table - <span>An Example of Lightweight jQuery Plugin for Beginners</span></h1>
<h2>Custom parse function Example</h2>
<div id="table"></div>

<script type="application/javascript" src="jQuery-3.2.1.min.js"></script>
<script src="../JSON-to-Table.min.1.0.1.js"></script>
<script type="application/javascript">
$(document).ready(function() {

var data = [
{
"id": 5123,
"first_name": "Alli",
"last_name": "Cassey",
"email": "acassey0@list-manage.com",
"gender": "Female",
"registered": false
},
{
"id": 5124,
"first_name": "Clyde",
"last_name": "Bromage",
"email": "cbromage1@bbb.org",
"gender": "Male",
"registered": true
},
{
"id": 5125,
"first_name": "Janeczka",
"last_name": "Trett",
"email": "jtrett2@vistaprint.com",
"gender": "Female",
"registered": null
},
{
"id": 5126,
"first_name": "Kristoforo",
"last_name": "Duplain",
"email": "kduplain3@vimeo.com",
"gender": "Male",
"registered": true
},
{
"id": 5127,
"first_name": "Devonna",
"last_name": "Medeway",
"email": "dmedeway4@google.nl",
"gender": "Female",
"registered": false
}
];

var parser = function(rowIdx, colIdx, value, isHead) {
if (String(value) == 'true')
value = '✔';
else if (String(value) == 'false')
value = '-';
else if (value == null)
value = '';
else if (String(value) == 'Male')
value = '👨🏻';
else if (String(value) == 'Female')
value = '👩🏻';
return (value);
}

$('#table').createTable(data, {
//showTableHeader: false,
showTableRowNumber: true,
//rowNumberInitialValue: 101,
colsSameWidth: false,
width: '80%',

parser: parser,
//parseHeader: true,
//parseRowNumber: true,
//parserCols: ['registered'],

showTitle: true,
titleText: 'My awesome table',
//titleAlign: 'left',

showFooter: true,
//footerText: 'My awesome footer',
footerAlign: 'right',

//debug: true
});

});//end jQuery
</script>
</body>
</html>
42 changes: 8 additions & 34 deletions Example/example.html → Example/Example.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<title>JSON Data To HTML Table - jQuery Plugin</title>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:300|Open+Sans+Condensed:300|Open+Sans:300"
rel="stylesheet">
<script src="jQuery-3.2.1.min.js"></script>
<script src="../JSON-to-Table.min.1.0.0.js"></script>
<style>
body {
font-family: 'Josefin Sans', sans-serif;
Expand Down Expand Up @@ -34,41 +32,17 @@
</style>
</head>
<body>

<h1>JSON Data To HTML Table - <span>An Example of Lightweight jQuery Plugin for Beginners</span></h1>
<h2>External JSON data file Example</h2>
<div class="table margin-bottom"></div>
<h2>JSON Object variable Example</h2>
<div id="table-2" class="margin-bottom"></div>
<script type="text/javascript">
$(document).ready(function () {
$.getJSON("sample-data.json", function (data) {
$('.table').createTable(data, {
// General Style for Table
borderWidth: '1px',
borderStyle: 'solid',
borderColor: '#DDDDDD',
fontFamily: 'Verdana, Helvetica, Arial, FreeSans, sans-serif',

// Table Header Style
thBg: '#F3F3F3',
thColor: '#0E0E0E',
thHeight: '30px',
thFontFamily: '"Open Sans Condensed", sans-serif',
thFontSize: '14px',
thTextTransform: 'capitalize',
<script src="jQuery-3.2.1.min.js"></script>
<script src="../JSON-to-Table.min.1.0.1.js"></script>
<div id="table" class="margin-bottom"></div>

// Table Body/Row Style
trBg: '#FFFFFF',
trColor: '#0E0E0E',
trHeight: '25px',
trFontFamily: '"Open Sans", sans-serif',
trFontSize: '13px',

// Table Body's Column Style
tdPaddingLeft: '10px',
tdPaddingRight: '10px'
});
});
<script type="text/javascript">
$(document).ready(function () {

var data = [{
"id": 1,
"first_name": "Alli",
Expand Down Expand Up @@ -140,7 +114,7 @@ <h2>JSON Object variable Example</h2>
"gender": "Male",
"ip_address": "243.29.74.93"
}];
$('#table-2').createTable(data, {});
$('#table').createTable(data, {});
});
</script>
</body>
Expand Down
76 changes: 76 additions & 0 deletions Example/External JSON Example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JSON Data To HTML Table - jQuery Plugin</title>
<link href="https://fonts.googleapis.com/css?family=Josefin+Sans:300|Open+Sans+Condensed:300|Open+Sans:300"
rel="stylesheet">
<style>
body {
font-family: 'Josefin Sans', sans-serif;
}

h1 {
font-size: 40px;
color: #08090d;
text-align: center;
}

h1 span {
font-size: 25px;
color: #477dd7;
}

h2 {
font-family: "Open Sans Condensed", sans-serif;
font-size: 18px;
}

.margin-bottom {
margin-bottom: 50px;
}
</style>
</head>
<body>
<h1>JSON Data To HTML Table - <span>An Example of Lightweight jQuery Plugin for Beginners</span></h1>
<h2>External JSON data file Example</h2>
<h4>⚠ Must run vai web server. CORS policy won't allow to load data locally.</h4>
<div class="table margin-bottom"></div>

<script src="jQuery-3.2.1.min.js"></script>
<script src="../JSON-to-Table.min.1.0.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {

$.getJSON("sample-data.json", function (data) {
$('.table').createTable(data, {
// General Style for Table
borderWidth: '1px',
borderStyle: 'solid',
borderColor: '#DDDDDD',
fontFamily: 'Verdana, Helvetica, Arial, FreeSans, sans-serif',

// Table Header Style
thBg: '#F3F3F3',
thColor: '#0E0E0E',
thHeight: '30px',
thFontFamily: '"Open Sans Condensed", sans-serif',
thFontSize: '14px',
thTextTransform: 'capitalize',

// Table Body/Row Style
trBg: '#FFFFFF',
trColor: '#0E0E0E',
trHeight: '25px',
trFontFamily: '"Open Sans", sans-serif',
trFontSize: '13px',

// Table Body's Column Style
tdPaddingLeft: '10px',
tdPaddingRight: '10px'
});
});
});
</script>
</body>
</html>
Loading