Refresh DataTable after deleting data not working

Refresh DataTable after deleting data not working

feedz87@yahoo.com.myfeedz87@yahoo.com.my Posts: 2Questions: 0Answers: 0

Hello,

I try for several hours to reload my dataTable, no success until now...

a.This is my code in js

     function DeleteData(id) {
            if(confirm('Are You Sure to Delete this Employee Record ?'))
            {
                $.ajax({
                    type: "POST",
                    url: '@Url.Action("Delete","Process")/' + id,
                    success: function (data) {
                        if (data.success)
                        {
                            DataTable.ajax.reload();
                        }
                    }
                });
            }
        }

b. This is my code in .net core controller

    [HttpPost]
    public ActionResult Delete(int id)
    {

        var process = _db.ProcessTbl.Where(e => e.ProcessID == id).FirstOrDefault();
         _db.Remove(process);
         _db.SaveChanges();

        return Json(new { success = true, data = process });

    }

Errors - No error shown but the datatable row not refresh after deleting data

I tried a lot of possibilities, no success.

Thank you in advance for your help.

Replies

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Is the if (data.success) on line 8 working as you expect? Meaning is it reaching the DataTable.ajax.reload(); statement?

    Have you used the browser's network inspector to verify the data.success value in the response?

    Can you post a link to your page or a test case showing the issue so we cn help debug?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • feedz87@yahoo.com.myfeedz87@yahoo.com.my Posts: 2Questions: 0Answers: 0
    edited August 2021

    Hi Kevin,

    1. if (data.success) is working properly and can reach the DataTable.ajax.reload();

    2. data.success value response = true

    3. network inspector result as follow :

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It would be worth looking at Editor since the API is designed to simplify this kind of operation.

    Colin

Sign In or Register to comment.