Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery dataTable reload from new ajax source

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

$('#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.

if (typeof obj == 'undefined') {

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

}
like image 603
Hector Barbossa Avatar asked Sep 13 '11 14:09

Hector Barbossa


2 Answers

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

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

var newUrl = "new.php";

oTable.fnReloadAjax(newUrl);
like image 105
Nicola Peluchetti Avatar answered Sep 20 '22 17:09

Nicola Peluchetti


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

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

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

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

like image 26
Matias Avatar answered Sep 17 '22 17:09

Matias