skip to Main Content

I am working with ASP.NET core(.NET 5)
The ajax.reload does not want to work for me.

The item gets deleted successfully and I get the toast successful message. But the datatable does not get refreshed.

var dataTable;

$(document).ready(function () {
loadDataTable();}); 

Unable to show the whole code for loadDataTable as too much code and unable to submit.
The table is working and data is being loaded.

function loadDataTable() {


dataTable = $('#tblData').DataTable({
    "ajax": {
        "url": "/Admin/Category/GetAll",
        "type": "GET",
        "datatype": "json"
    },

function Delete(url) {
swal({
    title: "Are you sure?",
    text: "Once deleted, you will not be able to recover",
    icon: "warning",
    dangerMode: true,
    buttons: true

}).then((willDelete) => {
    if (willDelete) {
        $.ajax({
            type: "DELETE",
            url: url,
            success: function (data) {
                if (data.success) {
                    toastr.success(data.message);
                    dataTable.ajax.reload();
                                    }
                else {
                    toastr.error(data.message);
               }
            }
        });
    }
});}

2

Answers


  1. Chosen as BEST ANSWER

    This what happens when you write code at midnight.

    Tried the code above same issue.

    Tried every reload.

    The issue was the If statement.

    if (data.success) {
    

    It was coming back undefined so was not even trying to reload.

    Sorted it and everything working.


  2. Try calling with the selector

    $('#tblData').DataTable().ajax.reload()
    

    If you’re using an older version, probably this one works

    $('#tblData').dataTable().api().ajax.reload();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search