MRocklin
MRocklin

Reputation: 57281

Redirect `sAjaxSource` in datatables and redraw

How can I point a DataTable to a different AjaxSource?

I want the content of my table to change based on the value of another form. Whenever that form changes I want my datatable to fetch new data from a different url and then redraw its contents.

I can't find anything like this in the docs. Can anyone suggest a good direction or, better yet, post example code snippets?

Upvotes: 3

Views: 375

Answers (2)

mattosmat
mattosmat

Reputation: 610

The information you need is in the custom api functions section. Take a look at the fnReloadAjax function; it allows you to change the data source and automatically updates and redraws your table.

Upvotes: 1

Federico J.
Federico J.

Reputation: 15912

I think that what you need is:

1 - Take the data from the external source, I mean, you want the new data, so you'll have to rebuild the table with your new data. Just drop the tbody part of the table when your form changes and then rebuild the tbody with the data you receive from the external url.

2 - Once you have redraw your tbody table, run .fnDraw() (you may read more here: https://datatables.net/api) to make sure DataTable will work with the new data.

If you have any doubt, just comment, ;)

Upvotes: 1

Related Questions