Reputation: 51
I'm using jquery datatables with version 1.10.12. I'm using dropdown to filters rows in datatables. I have server endpoints which returns data in json form (thanks to yajrabox for laravel). My question is how can I load new data into my existing instance Here is my code
var candidateDT = $("#candidates").DataTable({
processing: true,
serverSide: true,
ajax: '{!! url("/admin/candidates") !!}',
});
$(".filters").on('click', function(){
var url = '{{ url("admin/candidates/filters") }}';
var filterby = $(this).data('filter-by');
var value = $(this).val();
if(value !== ""){
$.ajax({
url:url,
data: {'filterby':filterby, 'value':value},
success: function(response) {
candidateDT.clear();
candidateDT.reload();
}
});
}
});
Where url is my endpoint for data source, and filters is my dropdown Thanks in advance
Upvotes: 2
Views: 1136
Reputation: 1776
There is with Ajax you can send more parameter to access from back-end. So you can try following way:
$("#candidates").DataTable({
processing: true,
serverSide: true,
ajax: {
url: '{!! url("/admin/candidates") !!}',
type: "get",
data: function(f) {
f.varname = $("#field").val(); //here place
}
},
});
Upvotes: 1