tfcmad
tfcmad

Reputation: 427

MVC Refreshing DataTables Data

I am using data tables along with MVC.

What I'm trying to achieve is updating the data inside a DataTable on 5 second interval, without refreshing the whole page, but I'm having trouble with the logic behind it.

At the moment I can populate the DataTable using my model or by using data returned in JSON format. But I seem to have problems with both.

Model Approach

JQuery calls a controller which returns a partial view which contains the whole table which has been populated. This works and is quite straight forward.

However it seems unnecessary to return the HTML every call, and since the table is being pulled in from a partial view, and each time page numbers and other settings are lost.

JSON Approach

JQuery calls a controller which returns the data we need in JSON format, this allows the relevant parts of the page to be updated.

However I don't see a way to update the data once it has been set, Apart from using DataTables built in AJAX call, which doesn't seem to allow for polling.

Any thoughts on whether these are good or bad approaches would be helpful.

Thanks,

Upvotes: 1

Views: 998

Answers (1)

iggyweb
iggyweb

Reputation: 2483

If the data source is MSSQL, then you could look at using SignalR and SQLDependency as per this example https://www.codeproject.com/Articles/874240/SignalR-Database-update-notifications-in-ASP-NET-M

Upvotes: 1

Related Questions