如何使用数据表和服务器端处理进行自定义过滤 [英] How to do custom filtering with Datatables and server-side processing

查看:90
本文介绍了如何使用数据表和服务器端处理进行自定义过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据表在我的Web应用程序中显示表格数据,并已对其进行配置以使用服务器端处理,即通过AJAX向服务器查询过滤后的数据.我想根据特定于我的应用程序的其他参数进行过滤,即与某些用户选项相对应(例如,通过用户界面中的复选框).如何使DataTables将这些其他过滤器参数传递给服务器?

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 data. I want to filter according to additional parameters that are specific to my application, i.e. corresponding to some user options (f.ex. via a checkbox in the UI). How do I make DataTables pass these additional filter parameters to the server?

推荐答案

解决方案是采用DataTables的 fnServerParams 选项,它允许您添加要发送到服务器的XMLHttpRequest中要发送的自定义参数.例如:

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});
    }
  });
});

这篇关于如何使用数据表和服务器端处理进行自定义过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆