datatables | fnreloadajax() is not working properl

2019-06-03 11:26发布

问题:

Im trying to reload the datatables from new ajax source.

i mean on page load it loads from 1 source, but after some action on page, it needs to be loaded from another source.

i am trying it through fnreloadajax() but it is not working, i mean all fnreload ajax do, it reloads the table but not from the new source??

i did read the docs for fnreloadajax() http://www.datatables.net/plug-ins/api/fnReloadAjax

but when i tried like this.

        var GroupID = e.val;
        url = "admin/usersManagePermissions/listFormsInGroups_DT/"+GroupID;
        oTable.fnReloadAjax(url);

i got no error, but also datatables dont reload the table from new source. it only loads the table from previous/original source which was defined to it.

what is wrong here?

回答1:

I had same problem today, here is my solution:

This is the datatable objet, be careful, DataTable() != dataTable() see this answer.

var tableRestr = $('#myDataTable').DataTable({
                    ajax: someUrl});

Then, always when I need to reload from another url, just use this two lines:

tableRestr.ajax.url(newUrl);
tableRestr.ajax.reload();