How to do custom filtering with Datatables and server-side processing

前端 未结 5 1760
面向向阳花
面向向阳花 2021-02-02 17:30

I am using Datatables to display tabular data in my Web application, and have configured it to make use of server-side processing, i.e. query the server via AJAX for filtered da

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-02 18:13

    The solution is to employ DataTables' fnServerParams option, which allows you to add custom parameters to be sent in the XMLHttpRequest sent to the server. For example:

    $(document).ready(function() {
      $('#example').dataTable({
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "/IndexXhr",
        "fnServerParams": function (aoData) {
            var includeUsuallyIgnored = $("#include-checkbox").is(":checked");
            aoData.push({name: "includeUsuallyIgnored", value: includeUsuallyIgnored});
        }
      });
    });
    

提交回复
热议问题