Reload dynamic dataTable

Reload dynamic dataTable

calinutzcalinutz Posts: 2Questions: 1Answers: 0
edited February 2016 in Free community support

Using Laravel, I use various Views containing each a DataTable with the same class, and different IDs. At any moment there is only one dataTable loaded in View (HTML). I get my data from ajax server side. My question is better explained here: http://stackoverflow.com/questions/35625882/jquery-dynamic-datatables-reload

I am trying to keep my javascript as clean as possible so I would like to be able to refer to the currently loaded dataTable and ajax.reload it. Something like this:

   $(".mydttable").ajax.reload();

//where mydttable is the class of every datatable I use in my project. This should work in my opinion, but it shows me "Processing..." and hangs there without reloading the dataTable.

I also tried:

                var idtable = $('.mydttable').attr("id");

                var table = $('#'+idtable);

                table.ajax.reload();

Nothing happens (I mean the delete part works, except for the reload part, where it does nothing)

I also tried:

   $('.mydttable').dataTable().fnReloadAjax();

Also nothing happens.

Is there any way I can achieve this?

Answers

  • calinutzcalinutz Posts: 2Questions: 1Answers: 0

    Is there a recommended way of using DataTables (multiple) with Laravel? Because I am having various difficulties using it that stops me from enjoying this amazing library

  • caohaiwangcaohaiwang Posts: 1Questions: 0Answers: 0

    I think you forgot to add "retrieve" option to the ajax option may you can try like this
    var table = $('#tableid').DataTable({
    paging: true,
    ...
    ajax: {
    url: '/somedatasource',
    dataSrc: "",
    retrieve: true,
    }...

    then when you need to reload you can use like this:
    table.ajax.reload();

This discussion has been closed.