2011-09-09 165 views
3

我正在使用JQuery SAjaxsource如何在SAjaxsource完成后调用JavaScript函数。我想更新一个div后的数据表load.Please完成帮我...如何在SAJAXSource完成JQuery数据表后调用javascript函数

编辑:

$(document).ready(function() { 
       var oTable = $('#example').dataTable({ 

        "bServerSide": true, 
            "sSearch":false, 
            "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], 
            "bPaginate": true, 
            "bJQueryUI": true, 
            "sPaginationType": "full_numbers", 
            "sAjaxSource": "server_processingCDB1.php" 
       }); 

回答

4

http://datatables.net/ref#fnDrawCallback也适用于这一点,并保存你需要到覆盖fnServerData。

参数: fnDrawCallback

类型:功能

输入: {对象}:数据表设置对象

该功能被称为对每一个 '画' 事件,并允许您动态修改您想要的关于创建的DOM的任何方面。

$(document).ready(function() { 
    $('#example').dataTable({ 
    "fnDrawCallback": function(oSettings) { 
     alert('DataTables has redrawn the table'); 
    } 
    }); 
}); 
+0

这是一个不完美的解决方案;当表格绘制时没有数据时,它会在页面加载时被调用,然后在数据加载时再次调用,这可能不太理想,具体取决于您的愿望。 – Erik

+0

它会在渲染数据之前调用。 –

6

看一看在的帮助下,回调部分fnServerData选项 - >http://www.datatables.net/usage/callbacks

为您提供所需的一切......这里的一些示例代码:

$(document).ready(function() { 
    $('#example').dataTable({ 
     "bProcessing": true, 
     "bServerSide": true, 
     "sAjaxSource": "../examples_support/server_processing.php", 
     "fnServerData": function (sSource, aoData, fnCallback) { 
      $.getJSON(sSource, aoData, function (json) { 
       /* Do whatever additional processing you want on the callback, then tell DataTables */ 
       fnCallback(json) 
      }); 
     } 
    }); 
}); 
+0

对不起,我编辑我的问题。我该如何调用javascript函数或如何更新div – Arasu

+0

谢谢! ManseUK。那为我做了诡计! – Packer

+0

即使我没有为 “sAjaxSource”提供任何文件路径,我也想让它工作。你能告诉我我该怎么做? – Packer

1

对于数据表版本1.10.12

$('#table_id').dataTable({ 
    ajax: function (data, callback, settings) { 
    $.ajax({ 
     url: '/your/url', 
     type: 'POST', 
     data: data, 
     success:function(data){ 
     callback(data); 
     } 
    }); 
    } 
}); 
相关问题