html - Table with two tbody's next to each other in table, thead on top -
i want create html table looks this:
left context | right context | delete row? ------------------------------------------- 1 [input] [input] y/n 2 [input] [input] y/n 3 [input] [input] y/n
this seems simple enough. thing want make rows sortable jquery ui. that's easy enough (call .sortable()
on tbody
), find ugly because number moves row. want "real" rows move, without indices (1, 2, 3 , on). numbers should in same spot, rows can move around.
i thought make new tbody inside table, after thead, contain numbers, , call .sortable on tbody contains rows. however, doesn't work: tables don't float next each other, placed above each other.
any ideas how deal this? test case on jsfiddle:
<table class="table table-hover table-striped"> <thead> <tr> <th></th> <th>left context</th> <th>right context</th> <th class="text-center">delete row?</th> </tr> </thead> <tbody> <tr><td>1</td></tr> <tr><td>2</td></tr> <tr><td>3</td></tr> <tr><td>4</td></tr> <tr><td>5</td></tr> <tr><td>6</td></tr> </tbody> <tbody class="sortable"> <tr class="ui-state-default"> <td> <input type="text" class="form-control left-context" value=""> </td> <td> <input type="text" class="form-control right-context" value=""> </td> <td> <button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i> </button> </td> </tr> <tr class="ui-state-default"> <td> <input type="text" class="form-control left-context" value=""> </td> <td> <input type="text" class="form-control right-context" value=""> </td> <td> <button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i> </button> </td> </tr> <tr class="ui-state-default"> <td> <input type="text" class="form-control left-context" value=""> </td> <td> <input type="text" class="form-control right-context" value=""> </td> <td> <button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i> </button> </td> </tr> <tr class="ui-state-default"> <td> <input type="text" class="form-control left-context" value=""> </td> <td> <input type="text" class="form-control right-context" value=""> </td> <td> <button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i> </button> </td> </tr> <tr class="ui-state-default"> <td> <input type="text" class="form-control left-context" value=""> </td> <td> <input type="text" class="form-control right-context" value=""> </td> <td> <button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i> </button> </td> </tr> <tr class="ui-state-default"> <td> <input type="text" class="form-control left-context" value=""> </td> <td> <input type="text" class="form-control right-context" value=""> </td> <td> <button type="button" class="btn btn-danger remove-row"><i class="fa fa-trash-o"></i> </button> </td> </tr> </tbody> </table>
i suggest using css counters in pseudo-elements displayed table-cells:
$("tbody").sortable(); $("button").on("click", function () { $(this).closest("tr").fadeout(300); });
@import 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'; td { padding: 8px; } thead > tr:before { content: ''; display: table-cell; } tbody { counter-reset: row-number; } tbody > tr:before { counter-increment: row-number; content: counter(row-number); display: table-cell; vertical-align: middle; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script> <table class="table table-hover table-striped"> <thead> <tr> <th>left context</th> <th>right context</th> <th>delete row?</th> </tr> </thead> <tbody> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><button type="button"><i class="fa fa-trash-o"></i></button></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><button type="button"><i class="fa fa-trash-o"></i></button></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><button type="button"><i class="fa fa-trash-o"></i></button></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><button type="button"><i class="fa fa-trash-o"></i></button></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><button type="button"><i class="fa fa-trash-o"></i></button></td> </tr> <tr> <td><input type="text"></td> <td><input type="text"></td> <td><button type="button"><i class="fa fa-trash-o"></i></button></td> </tr> </tbody> </table>
Comments
Post a Comment