【问题标题】:Success callback for Datatable server side processing ajax callDatatable服务器端处理ajax调用的成功回调
【发布时间】:2015-03-30 13:44:45
【问题描述】:

我想在我的服务器端调用完成后隐藏一些列

sAjaxSource: url,

在我完成使用fnCreatedRow 创建行之后。我想执行列可见性语句

table.fnSetColumnVis(0, false, false);

用于此回调中的多个列。有没有办法在数据表中做到这一点?我尝试过使用fnDrawCallbackfnRowCallback,但它们根本不执行。

我写的代码如下。

table = $('#ID').dataTable({
    "bServerSide": true,
    "bProcessing": true,
    "autowidth": true,
    //"bInfo": false,
    "dom": 'C<"clear">lfrtip',

    "scrollY": "350px",
    "scrollCollapse": false,
    "paging": true,
    "scrollX": true,
    "destroy":true,
    "sAjaxSource": url,
    "aoColumns": [
     {
           "targets": 0,
           //"bVisible": true,
           "title": "Select Client",
           "bSearchable": false,
           "bSortable": false,
           "width": "10%"
       },//Many such entries
    ],
    "fnCreatedRow": function (nRow, aaData, iDataIndex) {
     //Function body
    },
    "drawCallBack" : //Actual code that i want to get executed after fnCreatedRow has ended
});

【问题讨论】:

  • 获取数据后或绘制表格后是否要回调?
  • 表格绘制后
  • 你试过没有fn吗?只是drawCallback?你的代码中哪里有这个?如果它不在正确的位置,它将无法工作。

标签: jquery ajax datatables jquery-datatables


【解决方案1】:

试试这个:

"drawCallback": function(settings) {
               //do whatever
            }

https://datatables.net/reference/option/drawCallback

【讨论】:

  • 请注意,您提供的链接适用于 1.10 及以上版本。但问题中的参数名称表明 nnm 使用的是 1.10 之前的旧版 dataTables。
【解决方案2】:

我有一个类似的情况,我通过将 xhr 事件附加到我的数据表来解决它。

见:https://datatables.net/reference/event/xhr

 $table.on('xhr.dt',
        function (e, settings, data, xhr) {
            //do something with the 'data' returned from server
            //OR handle some error using the 'xhr' request
        });

在我的例子中,$table 是我在初始化数据表时预先声明的变量。

【讨论】:

    猜你喜欢
    • 2020-04-29
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    相关资源
    最近更新 更多