Search code examples
jqueryjsonajaxasp.net-mvcjqgrid

I need to update the changed row in the grid using ajax


I am new to jqGrid, I really need help.

After clicking on "submit" I want to update the row without reloading the page using Ajax. Tell what I need to write.

enter image description here

My code

I was able to update the data by updating the page, but I need it without an update

View

{
    //edit
    url: '@Url.Action("Edit", "TableDocument")',
    closeAfterEdit: true,
    height: 250,
    width: 400,
    afterSubmit: function(responce) {
        $("#jqg").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
        return [true, responce.responseText];
    }
},

Controller

    private static bool tuggel = false;
    private DataContext db = new DataContext();
    private Testing testing = new Testing();

    public TableDocumentController()
    {
        if (!tuggel)
        {
            testing.DataList();
            tuggel = true;
        }
    }

    public ActionResult Test()
    {
        return View();
    }

    public string GetData()
    {
        return JsonConvert.SerializeObject(db.DataBases);
    }


    [HttpPost]
    public void Edit(DataBase data)
    {
        try
        {
            db.Entry(data).State = EntityState.Modified;
            db.SaveChanges();
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
            throw;
        }
    }

Solution

  • You should use reloadAfterSubmit option set to false

    {
        //edit
        url: '@Url.Action("Edit", "TableDocument")',
        closeAfterEdit: true,
        reloadAfterSubmit : false,
        height: 250,
        width: 400,
        afterSubmit: function(responce) {
            $("#jqg").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
            return [true, responce.responseText];
        }
    },