"Panel table with filters (per column) TJN"
Bootstrap 3.3.0 Snippet by ityler

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.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 ----------> <div class="container"> <h3>The columns titles are merged with the filters inputs thanks to the placeholders attributes</h3> <hr> <p>Inspired by this <a href="https://bootsnipp.com/snippets/8G2Q">snippet</a></p> <div class="row"> <div class="panel panel-primary filterable"> <div class="panel-heading"> <h3 class="panel-title">Users</h3> <div class="pull-right"> <button class="btn btn-default btn-xs btn-filter"><span class="glyphicon glyphicon-filter"></span> Filter</button> </div> </div> <table class="table"> <thead> <tr class="filters"> <th><input type="text" class="form-control fxdcol" placeholder="TIMESTAMP" disabled></th> <th><input type="text" class="form-control smlcol" placeholder="JID" disabled></th> <th><input type="text" class="form-control" placeholder="CTLNUM" disabled></th> <th><input type="text" class="form-control" placeholder="MTHD" disabled></th> <th><input type="text" class="form-control" placeholder="REFERRER" disabled></th> <th><input type="text" class="form-control" placeholder="IP-ADDR" disabled></th> <th><input type="text" class="form-control" placeholder="STATUS" disabled></th> <th><input type="text" class="form-control" placeholder="VTD" disabled></th> </tr> </thead> <tbody> <tr> <td>05/23 13:25:21</td> <td>123</td> <td>12345678912</td> <td>TST</td> <td></td> <td>192.168.1.2</td> <td>VALID</td> <td>Y</td> </tr> <tr> <td>05/23 09:20:16</td> <td></td> <td>12345678900</td> <td></td> <td>HTTP://EXAMPLE.COM</td> <td>192.64.23.221</td> <td>INVLID MSG</td> <td>Y</td> </tr> <tr> <td>05/23 03:54:09</td> <td>953</td> <td>21654812647</td> <td>TST|EML</td> <td>HTTP://EXAMPLE.COM</td> <td>192.168.1.2</td> <td>VALID</td> <td>N</td> </tr> </tbody> </table> </div> </div> </div>
.filterable { margin-top: 15px; } .filterable .panel-heading .pull-right { margin-top: -20px; } .filterable .filters input[disabled] { background-color: transparent; border: none; cursor: auto; box-shadow: none; padding: 0; height: auto; } .filterable .filters input[disabled]::-webkit-input-placeholder { color: #333; } .filterable .filters input[disabled]::-moz-placeholder { color: #333; } .filterable .filters input[disabled]:-ms-input-placeholder { color: #333; } .smlcol { max-width:50px; } .fxdcol { width:100px; }
/* Please consider that the JS part isn't production ready at all, I just code it to show the concept of merging filters and titles together ! */ $(document).ready(function(){ $('.filterable .btn-filter').click(function(){ var $panel = $(this).parents('.filterable'), $filters = $panel.find('.filters input'), $tbody = $panel.find('.table tbody'); if ($filters.prop('disabled') == true) { $filters.prop('disabled', false); $filters.first().focus(); } else { $filters.val('').prop('disabled', true); $tbody.find('.no-result').remove(); $tbody.find('tr').show(); } }); $('.filterable .filters input').keyup(function(e){ /* Ignore tab key */ var code = e.keyCode || e.which; if (code == '9') return; /* Useful DOM data and selectors */ var $input = $(this), inputContent = $input.val().toLowerCase(), $panel = $input.parents('.filterable'), column = $panel.find('.filters th').index($input.parents('th')), $table = $panel.find('.table'), $rows = $table.find('tbody tr'); /* Dirtiest filter function ever ;) */ var $filteredRows = $rows.filter(function(){ var value = $(this).find('td').eq(column).text().toLowerCase(); return value.indexOf(inputContent) === -1; }); /* Clean previous no-result if exist */ $table.find('tbody .no-result').remove(); /* Show all rows, hide filtered ones (never do that outside of a demo ! xD) */ $rows.show(); $filteredRows.hide(); /* Prepend no-result row if all rows are filtered */ if ($filteredRows.length === $rows.length) { $table.find('tbody').prepend($('<tr class="no-result text-center"><td colspan="'+ $table.find('.filters th').length +'">No result found</td></tr>')); } }); });

Related: See More


Questions / Comments: