Tynamic Demo - Test 3
by maxeo
HTML
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
<script src="https://maxeo.github.io/tynamic/dist/tynamic.js"></script>
<table id="test4" class="table table-dark">
</table>
CSS
body{
background-color: #212529!important;
}
JavaScript
tynamic.updateTable(
document.getElementById("test4"),
{
'head': {
'class': "table-light",
'data': [{'html': '#', 'class': 'bg-danger'}, 'First', 'Last', 'Handle'],
},
'body': {
'class': 'table-dark',
'data': [
[{'tag': 'th', 'html': 1}, {'html': 'Mark', 'class': 'bg-warning text-dark'}, 'Otto', '@mdo'],
[2, 'Jacob', {'html': 'Thornton', 'attr': {'title': 'custom', 'style': 'color:red'}}, '@fat'],
[3, {'html': 'Larry the Bird', 'attr': {'colSpan': 2}}, {'html': '<button class="btn btn-success">button green</button>', 'f': 'clickMe'}],
]
}
}, {
clickMe: function (data, td) {
let btn = td.querySelector('button');
btn.addEventListener('click', function () {
if (btn.classList.contains('btn-success')) {
btn.innerHTML = 'button red';
btn.classList.remove('btn-success');
btn.classList.add('btn-danger');
} else {
btn.innerHTML = 'button green';
btn.classList.add('btn-success');
btn.classList.remove('btn-danger');
}
})
}
}
)