Search code examples
jqgridjqgrid-asp.netmvcjqgrid

JQGrid Form Edit/View Customizing the Template form data


I am using jqGrid form Edit with templating from the link in Here

But Whenever a user clicks Edit/View I don't want to rely on the data which is on the grid but I want to get a new fresh data from the server and populate the form.

So I have the following jquery function which gets fresh data on the row being Edited,

function GetItem(id) {
    $.ajax({
        url: '/Asset/GetSingleItem/'+id,
        type: 'GET',
        success: function (data) {
            //Data is the json that i want to show on my Edit form.
        }
    });
}

I guess the solution is to override the OnRowEdit/View of the jqgrid and do some trick.


Solution

  • You could start $.ajax request in the beforeShowForm callback of form editing for example (see the documentation). Inside of success handler you can compare the data returned from the server with the data in the edit form. You need just know that the id of every field of the form is the same as the value of the name property in the corresponding column of colModel. If the server response have more recent data you can set the properties in the from (using $.val) and to use setRowData to refresh the row data in the grid too. The hidden filed of the form with id="id_g" can be used to get the rowid of editing row ($("#id_g").val()).