"Calculated tables"
Bootstrap 3.2.0 Snippet by LaunchaRoow

<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> <div class="container"> <div class = "col-md-10 table-responsive"> <div class="row clearfix"> <div class="col-md-12 table-responsive"> <table class="table table-hover table-sortable" id="calc_logic"> <thead> <tr> <th class="text-center"> Calculated Channels </th> <th class="text-center"> Formulas </th> <th class="text-center"> Variables </th> <th class="text-center" style="border-top: 1px solid #ffffff; border-right: 1px solid #ffffff;"> </th> </tr> </thead> <tbody> <tr id='addr0' data-id="0" class="hidden"> <td data-name="name"> <input type="text" name='name0' placeholder='Channel Name' class="form-control"/> </td> <td data-name="formula"> <input type="text" name='formula0' placeholder='Formula' class="form-control"/> </td> <td data-name="variables"> <div class="column"> <label for="variable0" class = "center-block">Variable "a"</label> <input type="variable0" name='variable0' placeholder='Name1' class="form-control"/> <label for="variable1" class = "center-block">Variable "b"</label> <input type="variable1" name='variable1' placeholder='Name2' class="form-control"/> <br> <a id="add_variable" class="btn btn-default center-block">Add Variable</a> </div> </td> <td data-name="del"> <button nam"del0" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button> </td> </tr> </tbody> </table> </div> </div> <a id="add_row" class="btn btn-default pull-right">Add Calculated Channel</a> </div> <div class="col-md-2 table-responsive"> <div class="row clearfix"> <div class="col-md-12 table-responsive"> <table class="table table-bordered table-hover table-sortable" id="names"> <thead> <tr > <th class="text-center"> Name </th> </tr> </thead> <tbody> <tr id='addr0' data-id="0" class="hidden"> <td data-name="name"> <input type="text" name='name0' placeholder='Name' class="form-control"/> </td> <td data-name="del"> <button nam"del0" class='btn btn-danger glyphicon glyphicon-remove row-remove'></button> </td> </tr> </tbody> </table> </div> </div> <a id="add_channel" class="btn btn-default pull-right">Add Channel</a> </div> </div>
.table-sortable tbody tr form-control { cursor: move; }
$(document).ready(function() { $("#add_row").on("click", function() { // Dynamic Rows Code for the calc table. // Get max row id and set new id var newid = 0; $.each($("#calc_logic tr"), function() { if (parseInt($(this).data("id")) > newid) { newid = parseInt($(this).data("id")); } }); newid++; var tr = $("<tr></tr>", { id: "addr"+newid, "data-id": newid }); // loop through each td and create new elements with name of newid $.each($("#calc_logic tbody tr:nth(0) td"), function() { var cur_td = $(this); var children = cur_td.children(); // add new td and element if it has a nane if ($(this).data("name") !== undefined) { var td = $("<td></td>", { "data-name": $(cur_td).data("name") }); var c = $(cur_td).find($(children[0]).prop('tagName')).clone().val(""); c.attr("name", $(cur_td).data("name") + newid); c.appendTo($(td)); td.appendTo($(tr)); } else { var td = $("<td></td>", { 'text': $('#calc_logic tr').length }).appendTo($(tr)); } }); // add delete button and td /* $("<td></td>").append( $("<button class='btn btn-danger glyphicon glyphicon-remove row-remove'></button>") .click(function() { $(this).closest("tr").remove(); }) ).appendTo($(tr)); */ // add the new row $(tr).appendTo($('#calc_logic')); $(tr).find("td button.row-remove").on("click", function() { $(this).closest("tr").remove(); }); }); // Sortable Code var fixHelperModified = function(e, tr) { var $originals = tr.children(); var $helper = tr.clone(); $helper.children().each(function(index) { $(this).width($originals.eq(index).width()) }); return $helper; }; $(".table-sortable tbody").sortable({ helper: fixHelperModified }).disableSelection(); $(".table-sortable thead").disableSelection(); $("#add_row").trigger("click"); // $("#add_channel").trigger("click"); });

Related: See More


Questions / Comments: