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.

cedric_jumiacedric_jumia Posts: 2Questions: 1Answers: 0
edited September 2016 in Free community support

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 :smile:

$('"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

  • allanallan Posts: 63,815Questions: 1Answers: 10,517 Site admin

    Is there any way to perform this task ?

    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

  • cedric_jumiacedric_jumia Posts: 2Questions: 1Answers: 0

    Thanks Allan,
    Actually I figured out a workaround, by adding another step to the process.

    Thanks again !

This discussion has been closed.