jquery DataTables Reload without page refresh

Viewed 3410

I am using jQuery DataTables and here is what my table currently looks like:

enter image description here

Now, as of right now when I click Deactivate I am using ajax to call my WebApi method to set that record to active = false.. so the checkbox in the table should be unchecked.

public IHttpActionResult Deletecode_AutoMake(int id)
{
    code_AutoMake code_AutoMake = db.code_AutoMake.Find(id);
    if (code_AutoMake == null)
    {
        return NotFound();
    }

    code_AutoMake.Active = false;
    db.Entry(code_AutoMake).State = EntityState.Modified;
    db.SaveChanges();

    return Ok(code_AutoMake);
}

This all works as expected.. but the table doesn't reload, unless if I refresh the page to see the check box actually unchecked.

Here is how my DataTable is set up.

$("#Auto-Make-Table").on("click",
    ".js-automake-delete",
    function () {

        var link = $(this);
        var autoMakeName = $(this).data("automake-name");
        var autoMakeId = $(this).data("automake-id");

        bootbox.confirm("Are you sure you want to delete this auto make?",
            function (result) {
                if (result) {
                    $.ajax({
                        url: infoGetUrl + autoMakeId,
                        method: "DELETE",
                        success: function () {
                            autoMakeTable.reload();
                            toastr.success(autoMakeName + " successfully deleted");
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            var status = capitalizeFirstLetter(textStatus);
                            var error = $.parseJSON(jqXHR.responseText);
                            console.log(error);
                            toastr.error(status + " - " + error.exceptionMessage);
                        }
                    });
                }
            });
    });

My question/goal is.. how do I get the table to refresh/reload itself without an actual page refresh?

Any help is appreciated.

UPDATE

Tried using autoMakeTable.ajax.reload();

Received this error:

enter image description here

Followed by this one:

enter image description here

2 Answers
Related