jQuery dataTable 从新的 ajax 源重新加载

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7403985/
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-08-26 23:48:14  来源:igfitidea点击:

jQuery dataTable reload from new ajax source

jquerydatatables

提问by Hector Barbossa

I am using jquery Datatable plugin. The init code is like below

我正在使用 jquery 数据表插件。初始化代码如下

$('#Table').dataTable( {
    "sAjaxSource": url
    ...
    ...
}); 

which gets fired on click of a button.Now on click of that button again I want to get the dataTable with a different url. I have tried using without success.Please suggest.

单击按钮时会被触发。现在再次单击该按钮,我想获取具有不同 url 的数据表。我试过使用没有成功。请建议。

if (typeof obj == 'undefined') {

    obj = $('#Table').dataTable( {
    "sAjaxSource": url
    ...
    ...
    })
}else
{
    obj.fnClearTable(0);
    obj.fnDraw(false);

}

回答by Nicola Peluchetti

I think what you need is fnReloadAjax(). You should use it like this:

我认为你需要的是fnReloadAjax()。你应该像这样使用它:

var oTable = $('#Table').dataTable( {
    "sAjaxSource": url
    ...
    ...
}); 

var newUrl = "new.php";

oTable.fnReloadAjax(newUrl);

回答by Matias

Try with this link: http://datatables.net/reference/api/ajax.url()

试试这个链接:http: //datatables.net/reference/api/ajax.url()

var table = $('#example').DataTable( { ajax: "data.json" } );
table.ajax.url( 'newData.json' ).load();

var table = $('#example').DataTable( { ajax: "data.json" } );
table.ajax.url('newData.json').load();

or as I did if table is not a dataTable object:

或者就像我所做的那样,如果 table 不是 dataTable 对象:

$('#tableId').DataTable().ajax.url("newUrl").load();

$('#tableId').DataTable().ajax.url("newUrl").load();

回答by Pande

This work for me:

这对我有用:

var table = $('#Table').dataTable( {
    "sAjaxSource": url
    ...
    ...
}); 

url = 'newajax.php';

console.log('change input listened');
table.ajax.url(url);
table.draw();

回答by major

This worked for version 1.10:

这适用于 1.10 版:

   oTable.ajax.url("new_source_file.php");
   oTable.draw();