Datatable服务器端处理Ajax调用的成功回调

4

当我完成服务器端调用并创建完使用fnCreatedRow的行后,我希望隐藏一些列。 我想在此回调中为多个列执行列可见性语句,代码如下:

sAjaxSource: url,

table.fnSetColumnVis(0, false, false);

在datatable中有没有办法实现这样的功能? 我已经尝试使用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
});

你想在获取数据后还是绘制表格后回调? - jonmrich
绘制表格后,请返回已翻译的文本。 - nnm
你试过不用 fn 吗?只用 drawCallback?这段代码放在哪里?如果不是正确的位置,它就不会起作用。 - jonmrich
2个回答

11

2
请注意,您提供的链接适用于1.10及以上版本。但问题中的参数名称表明nnm正在使用早于1.10的dataTables遗留版本。 - Moonchild

3
我曾经遇到过类似的情况,我通过将xhr事件附加到我的datatable来解决它。
参见: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是我在初始化数据表时预先声明的变量。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接