Skip to content

Instantly share code, notes, and snippets.

@elton182
Created December 8, 2017 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elton182/e757aeec412d53e8e7e5464c63f2fe2f to your computer and use it in GitHub Desktop.
Save elton182/e757aeec412d53e8e7e5464c63f2fe2f to your computer and use it in GitHub Desktop.
datatable com filtros em colunas
<div class="table-responsive">
<table class="table table-bordered table-striped table-responsive" id="table" cellpadding="0" cellspacing="0" width="100%">
<thead>
<tr>
<th>Nome</th>
<th>Telefone</th>
<th>Celular</th>
<th>Data Nascimento</th>
<th>Ações</th>
</tr>
</thead>
<thead class="hidden-xs hidden-sm hidden-md datatable-filter">
<tr>
<th>
<input type="text" class="form-control search-input-text" data-column="0" style="width: 100%">
</th>
<th>
<input type="text" class="form-control search-input-text" data-column="1" style="width: 100%"">
</th>
<th>
<input type="text" class="form-control search-input-text" data-column="2" style="width: 100%"">
</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
table = $('#table').DataTable({
responsive: true,
"bAutoWidth": false,
ajax: {
url :'{{action('YourController@getTableData')}}',
type: 'POST'
},
"order": [[ 1, "asc" ]],
columns: [
{ data: 'name' , name: 'name' },
{ data: 'phone' , name: 'phone' },
{ data: 'celphone' , name: 'celphone' },
{ data: 'born_date_year' , name: 'born_date_year' },
{ data: 'actions' , name: 'actions' },
],
});
$('#table .search-input-text').on( 'keyup change', function () { // for text boxes
var i =$(this).attr('data-column'); // getting column index
var v =$(this).val(); // getting search input value
table.columns(i).search(v).draw();
// dataTable.ajax.reload( null, false );
} );
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment