在 JQuery 数据表中完成 SAjaxsource 后如何调用 javascript 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7360861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 23:51:32  来源:igfitidea点击:

How to Call a javascript function after SAjaxsource completes in JQuery Datatables

javascriptjquerydatatables

提问by Arasu

I'm using JQuery SAjaxsource How can i Call a javascript function after SAjaxsource completes. I want to update a div after the completion of the datatable load.Please help me...

我正在使用 JQuery SAjaxsource 如何在 SAjaxsource 完成后调用 javascript 函数。我想在数据表加载完成后更新一个div。请帮帮我...

Edit:

编辑:

$(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"
                } );

回答by Manse

take a look at the fnServerData option in the callbacks section of the help -> http://www.datatables.net/usage/callbacks

查看帮助的回调部分中的 fnServerData 选项 -> http://www.datatables.net/usage/callbacks

Gives you everything you need ... here some example code :

给你你需要的一切......这里有一些示例代码:

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

回答by Allan

http://datatables.net/ref#fnDrawCallbackalso works for this, and saved you needing to override fnServerData.

http://datatables.net/ref#fnDrawCallback也适用于此,并节省您需要覆盖 fnServerData。

Parameter:fnDrawCallback

Type:function

Inputs:{object}: DataTables settings object

This function is called on every 'draw' event, and allows you to dynamically modify any aspect you want about the created DOM.

参数:fnDrawCallback

类型:函数

输入:{object}:DataTables 设置对象

这个函数在每个“绘制”事件上被调用,并允许你动态修改你想要的关于创建的 DOM 的任何方面。

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

回答by Khalid

For datatables version 1.10.12

对于数据表版本 1.10.12

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