【问题标题】:How to add individual column search with serverside datatable using ajax request如何使用 ajax 请求在服务器端数据表中添加单独的列搜索
【发布时间】:2022-12-01 16:38:23
【问题描述】:

我试图在服务器端数据表中添加单独的列搜索,但它不起作用。

  // Apply the filter
    $("#empTable tfoot input").on( 'keyup change', function () { alert('test');
        tables
            .column( $(this).parent().index()+':visible' )
            .search( this.value )
            .draw();
    } );

我需要这个如何在数据表中实现的解决方案

【问题讨论】:

  • 这不足以理解您要实现的目标。请尝试添加最少的可重现步骤。

标签: php ajax


【解决方案1】:

假设您将过滤列名,将此输入添加到顶部列名

<input type="text" class="name_filter reload_datatable">

将您的 ajax 数据表更改为此

var table = $(".table").DataTable({
  "ajax": {
    "url": "urlajax",
    "dataType": "json",
    "type": "post",
    "data": function(d) {
      d.name= $('.name_filter').val()
    }
  }
}

在这样的变化上创建函数

$(".reload_datatable").change(function(){
  table.ajax.reload();
});

并使用 ajax php 获取数据

$_POST['name']

【讨论】:

    猜你喜欢
    • 2014-05-31
    • 1970-01-01
    • 2021-08-02
    • 2015-03-11
    • 1970-01-01
    • 2016-09-23
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    相关资源
    最近更新 更多