<html>
<head>
<meta name="description" content="Simple table">
<meta charset="utf-8">
<title>Simple table</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<link href="https://nightly.datatables.net/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script src="https://nightly.datatables.net/js/jquery.dataTables.js"></script>
</head>
<body>
<table width="100%" class="display" id="example" cellspacing="0">
<thead>
<tr><th>Col A</th><th>Col b</th><th>Input A</th><th>Input B</th></tr>
</thead>
<button type='button'>go</button>
<tbody></tbody>
<tfoot></tfoot>
</table>
</body>
</html>
$(function($){
$("tbody", "#example").on("click", "td",
function() {alert(this.innerText); }) ;
var dataStore = [];
for(var i = 0; i < 25; ++i){
var a = Math.floor((Math.random() * 100) + 1);
var b = Math.floor((Math.random() * 100) + 1);
dataStore[dataStore.length] = {ColumnA:a, ColumnB:b};
}
table = $('#example').DataTable( {
dom:"iptlf",
"data": dataStore,
"columnDefs":[{targets:[2,3], render:function(){return '<input type="text" value="0" size="10"/>';}}],
"columns": [
{ "data": function(a, b, c, d){debugger;}, "title":"ColumnA", "defaultContent": "NA" },
{ "data": "ColumnB", "title":"ColumnB", "defaultContent": "NA" },
{ "data": null, className:"inputA", "title":"Input A"},
{ "data": null, className:"inputB", "title":"Input B"}
]
});
$("#example .inputA").on("change", "input", function(){doTable(this, "ColumnA");});
$("#example .inputB").on("change","input", function(){doTable(this, "ColumnB");});
$("button").click(function(){
console.log(table.$('input').serialize());
});
});
function doTable (target, name){
var $row = $(target).closest("tr");
var addVal = $(target).val();
var data = $("#example").DataTable().rows($row).data()[0];
data[name] = parseInt(addVal) + data[name];
$("#example").DataTable().rows($row).invalidate().draw();
}
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |