Call an "initComplete": function()

Call an "initComplete": function()

chessGuru64chessGuru64 Posts: 79Questions: 18Answers: 1
edited February 2019 in Free community support

When someone adds or deletes from their cart https://datatables-ecommerence.000webhostapp.com/ I need to refresh the new item count. What is the easiest way to call the initComplete function?

"initComplete": function(settings, json){ 
        var info = this.api().page.info();
        $(".shoppingbasket").append("<div class='basketitems'>" + info.recordsTotal + "</div>");
}

Howcome one cannot type it as a regular function count (settings, json){

I could do it the AJAX way something like: $("#cart").load('https://datatables-ecommerence.000webhostapp.com/' + "#cartCount"); if that is more simple.

Answers

  • chessGuru64chessGuru64 Posts: 79Questions: 18Answers: 1
    edited February 2019

    I accidentally figured out the solution by guessing:

    I changed initFunction to:

    drawCallback: function () {

    My original question theoretically still stands though, is there an easy way to call an initFunction?

  • kthorngrenkthorngren Posts: 21,309Questions: 26Answers: 4,947

    The initComplete is executed once after the Datatables has initialized. There is not a way to call the function directly. However the initComplete function can call a function you define which is available to use in other areas of your code.

    Kevin

This discussion has been closed.