Created
January 19, 2017 08:31
-
-
Save phpfour/0c098cc9f1412ccc2281d87b8c6f09cf to your computer and use it in GitHub Desktop.
Datatable Filtering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(function () { | |
var $table = $('#candidates'); | |
var $dataTable = $table.DataTable({ | |
"paging": true, | |
"lengthChange": false, | |
"searching": true, | |
"ordering": true, | |
"order": [[5, 'desc']], | |
"processing": true, | |
"serverSide": true, | |
"ajax": "{{ path('admin_candidates_list') }}", | |
"columns": [ | |
{ | |
"data": "first_name", | |
"name": "first_name", | |
"searchable": true, | |
"orderable": false | |
}, | |
{ | |
"data": "last_name", | |
"name": "last_name", | |
"searchable": true, | |
"orderable": false | |
}, | |
{ | |
"data": "campaign_title", | |
"name": "campaign_title", | |
"searchable": false, | |
"orderable": true | |
}, | |
{ | |
"data": "company_name", | |
"name": "company_name", | |
"searchable": false, | |
"orderable": true | |
}, | |
{ | |
"data": "current_stage", | |
"name": "current_stage", | |
"searchable": true, | |
"orderable": false, | |
"className": "dt-center" | |
}, | |
{ | |
"data": "created_at", | |
"name": "created_at", | |
"searchable": false, | |
"orderable": false, | |
"className": "dt-center" | |
}, | |
{ | |
"data": null, | |
"name": "action", | |
"className": "dt-center", | |
"width": "7%", | |
"render": function (data, type, row) { | |
return '<a href="' + row.resume_link + '" target="_blank" class="btn btn-xs btn-default">Download</a>'; | |
} | |
} | |
], | |
"initComplete": function () { | |
var html = '<label>Filter by Stage:</label> ' + | |
'<select id="stage-filter" class="form-control">' + | |
'<option>All</option>' + | |
'<option value="Prospects">Prospects</option>' + | |
'<option value="Candidates">Candidates</option>' + | |
'<option value="Hired">Hired</option>' + | |
'</select>'; | |
$('#candidates_wrapper').find('.col-sm-6').first().append(html); | |
$('#stage-filter').on('change', function(){ | |
$dataTable.column(4).search($(this).val()).draw(); | |
}); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment