【问题标题】:in datatable initComplete not called after table.ajax.reload();在 table.ajax.reload() 之后未调用数据表 initComplete;
【发布时间】:2019-05-28 16:06:44
【问题描述】:

initComplete 的数据表中,我写了一些代码。第一次工作正常,但在调用 table.ajax.reload() 之后,initComplete 没有在数据表中执行。

"initComplete": function(settings, json) {
  $("#customerBids tr.cls-x-setTr").each(function() {
    debugger;
    var trId = $(this).attr('id');
    $('#' + trId + ' td').hide();
    $('#' + trId).append('<td class="cls-x-tmpTD" colspan="18"> </td>');
  });
},

我添加了这个造成问题的间隔:

timer = setInterval(function() { 
  table.ajax.reload(null, false); 
}, 15000);

【问题讨论】:

    标签: jquery asp.net-mvc datatable


    【解决方案1】:

    reload() 的第一个参数是要执行的回调函数的引用。因此,您可以将 initComplete() 逻辑提取到它自己的函数中,该函数从两个事件中调用。试试这个:

    // in datatable settings:
    "initComplete": foo,
    
    // your reload logic:
    timer = setInterval(function() { 
      table.ajax.reload(foo, false); // note 'foo' here
    }, 15000);
    
    // somewhere outside of your datatable definition:
    function foo() {
      $("#customerBids tr.cls-x-setTr").each(function() {
        debugger;
        var trId = $(this).attr('id');
        $('#' + trId + ' td').hide();
        $('#' + trId).append('<td class="cls-x-tmpTD" colspan="18"> </td>');
      });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-13
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多