0

I have a checkbox in my datatables table header that I'm trying to pass as a parameter for server side processing. It seems like this should be trivial, but I'm either overlooking something or I am missing something with how datatables works.

This is my input:

<input id="active-users-chk" type="checkbox" name="active-users-chk" checked="checked"> Active Users Only

This works outside of the datatables initialization:

$('#active-users-chk').on('change', function(){
    console.log($('#active-users-chk').is(':checked') ? 1 : 0);
    $('#mng-users-table').DataTable().ajax.reload();
});

but if I try to use it dynamically as an ajax.data parameter, it's always true:

"ajax": {
   "url": baseUrl + 'admin/get_users',
   "type": "POST",
   "data": {
     "active_only": $('#active-users-chk').is(':checked')
   }
},

I've tried everything I can think of, but can't seem to get this to work within the datatables initialization.

2
  • it works if i hard-code the value. Commented Sep 23, 2018 at 18:17
  • hmm also try adding "serverSide": true, option property Commented Sep 23, 2018 at 18:25

1 Answer 1

1
"ajax": {
              "url": baseUrl + 'admin/get_users',
              "type": "POST",
              "data": function(d) {
                d.active_only = $('#active-users-chk').is(':checked') ? 1 : 0;
              }
          },

per this SO answer

Sign up to request clarification or add additional context in comments.

1 Comment

Great. It worked. I was able to send the updated state of my checkbox. Thanks.

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.