2

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

1
  • 1
    You can destroy and recreate datatable that would be easy to use filter Commented Jan 23, 2018 at 5:55

1 Answer 1

1

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
        }
    },
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.