来自新来源的数据库ajax​​重新加载 [英] datatables ajax reload from new source

查看:182
本文介绍了来自新来源的数据库ajax​​重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用新的ajax功能重新加载数据表?

How do I reload datatables with the new ajax functionality?

我认为这是一个范围问题。

I think it's a problem of scope.

function load_table(tableName,src)
{
    var oTable = $('#'+tableName).DataTable({
          'bProcessing'    : true,
          'bServerSide'    : true,
          'responsive' : true,
          'sAjaxSource'    : src,

        'fnServerData'   : function(sSource, aoData, fnCallback)
          {
            $.ajax({
              'dataType': 'json',
              'type'    : 'POST',
              'url'     : sSource,
              'data'    : aoData,
              'success' : fnCallback
            }); 
          }, 
     });
}

尝试从不同的数据源重新加载它:

Try to reload it from a different data source:

$("input[type="button"]").on('click',function()
{

oTable.ajax.url( 'newsource' ).load();
alert( 'Data source: '+oTable.ajax.url() );


});

警报输出:src:newsource

浏览器从src加载表:oldsource

推荐答案

对于将来遇到这个问题的任何人来说,同样的问题是解决方案:

I've had the same issue to anyone who runs into this problem in the future here is the solution:

要从不同的源重新加载数据:

To accomplish reloading of data from a different source:

参考DOM表元素 DataTable对象,否则您将收到重新启动错误:

refer to the DOM table element NOT the DataTable object or you will get a reinitilization error:

步骤1 :清除数据:

$('#your_table_name').DataTable().clear();

步骤2:销毁DataTable对象

step 2: Destroy the DataTable object

 $('#your_table_name').DataTable().destroy();

如果你使用子行这是非常重要的删除点击监听器

if you're using child rows this is very important remove the click listener

   $( "#your_table_name tbody" )
    .off( "click", "td.details-control");

Reinit DataTables:

Reinit DataTables:

loadTable('newsource','your_table_name')

和您的loadTable函数

and your loadTable function

function loadTable(src,tableName)
{
var oTable = $('#'+tableName).DataTable({
  'bProcessing'    : true,
  'bServerSide'    : true,
        'responsive' : true,
         "sDom": '<"toolbar"lfr>tip<"F">R',

  'sAjaxSource'    : src,

   });

  //initchildrows()
}

这篇关于来自新来源的数据库ajax​​重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆