数据服务器端处理ajax调用的成功回调

时间:2015-03-30 13:44:46

标签: jquery ajax datatables jquery-datatables

我想在服务器端调用完成

中指定的URL后隐藏一些列

sAjaxSource: url

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

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

2 个答案:

答案 0 :(得分:7)

试试这个:

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

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

答案 1 :(得分:0)

我有类似的情况,我通过将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是我在初始化数据表时预先声明的var。