Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<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

Dismiss x
public
Bin info
bindridpro
0viewers