Is it possible to refresh a DataTable with a new JSON datasource generated serverside.
Is it possible to refresh a DataTable with a new JSON datasource generated serverside.
Hi,
First of all, thank for this amazing project. It helped me a lot.
However, I am facing difficulties. I am trying to refresh a DataTable handled server-side (bServerSide = true") by feeding it with a JSON generated by the server, based on user form submission (post).
I did not found any way to redraw the DataTable with this newly created JSON. I checked the documentation but I failed to retrieve relevant informations about this matter.
Is there any way to perform this task ?
Please find hereafter a snippet of the code
$('"form_id').submit(function (e) {
e.preventDefault();
$.ajax(
{
url : urlToSendPostData,
type: "POST",
data : $(this).serializeArray(),
success:function(data, textStatus, jqXHR)
{
//Redraw datatable with JSON (contained in data parameter)
},
error: function(jqXHR, textStatus, errorThrown)
{
//if fails ...
}
});
return false;
});
Sincerely yours,
Answers
No - sorry. You cannot get your JSON data from some other source and then feed it to DataTables. You need to call
draw()
to refresh / redraw the table if you are using server-side processing and DataTables will make its own Ajax call to get the data.Allan
Thanks Allan,
Actually I figured out a workaround, by adding another step to the process.
Thanks again !