Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: JQGrid
I am using JQGrid I am able to edit the row in popup page and post the data but the grid is not loading with current(Updated) data after submit.
 
Below Is the my code:
var result;
        //gets the data and adds each row
        function getData() {
            jQuery.ajax({
                url: '/Customer/GetCustomers',
                datatype: "Json",
                async: false,
                complete: function (jsondata, stat) {
                    if (stat == "success") {
                        result = JSON.parse(jsondata.responseText);
                        $(result).each(function (e) {
                            var p = new Date(this["Customer_Start_Dt"]);
                            $("#list1").addRowData(e, this);
                        });
                    }
                }
            });
        }
        //get all Location Type
        var locations = jQuery.ajax({
            url: '/Customer/GetLocations',
            datatype: "Json",
            async: false,
            success: function (data, result1) {
                if (!result1) alert('Failure to retrieve the Location Type.');
            }
        }).responseText;
 
$(document).ready(function () {
           var lastsel;
           debugger;
           // Set up the jquery grid
           $("#list1").jqGrid({
 
               // Ajax related configurations
               //url: jqDataUrl,
               datatype: "json",
               mtype: "get",
               //loadonce: true,
               // Specify the column names
               colNames: ["Customer Id", "Customer Location", "Customer Name", "Categories Sold", "Credit Period", "Customer Start Date", "Customer End Date","Location"],
 
               // Configure the columns
               colModel: [
               {
                   name: "Customer_Id", index: "Customer_Id", width: 150, align: "left",
                   sorttype: "int", key: true, editable: true, editrules: { edithidden: false },
                   hidedlg: true, hidden: true
               },
               {
                   name: "Location_Type", index: "LOCATION.Location_Type", width: 150, align: "left",
                   sorttype: "float", sortable: true
               },
               {
                   name: "Customer_Name", index: "Customer_Name", width: 150,
                   editable: true, edittype: "text", align: "left",
                   sorttype: "float", sortable: true, editrules: { required: true }
               },
               {
                   name: "Categories_Sold", index: "Categories_Sold", width: 150,
                   editable: true, edittype: "text", align: "left", sorttype: "float",
                   editrules: { required: true },
                   editoptions: {
                       size: 15, maxlengh: 10,
                       dataInit: function (element) {
                           $(element).keyup(function () {
                               var val1 = element.value;
                               var num = new Number(val1);
                               if (isNaN(num))
                               { alert("Please enter a valid number"); }
                           })
                       }
                   }
 
               },
               {
                   name: "Credit_Period", index: "Credit_Period", width: 150,
                   editable: true, edittype: "text", align: "left",
                   sorttype: "float", editrules: { required: true },
                   editoptions: {
                       size: 15, maxlengh: 10,
                       dataInit: function (element) {
                           $(element).keyup(function () {
                               var val1 = element.value;
                               var num = new Number(val1);
                               if (isNaN(num))
                               { alert("Please enter a valid number"); }
                           })
                       }
                   }
               },
               {
                   name: 'Customer_Start_Dt', height: 100, index: 'Customer_Start_Dt', align: 'right', sortable: false,
                   formatter: 'date', formatoptions: { newformat: 'm/d/y' }, editable: true,
                   editrules: { required: true },
                   editoptions: {
                       readonly: 'readonly',
                       dataInit: function (el) { $(el).datepicker(); }
                   }
               },
               {
                   name: 'Customer_End_Dt', height: 100, index: 'Customer_End_Dt', align: 'right', sortable: false,
                   formatter: 'date', formatoptions: { newformat: 'm/d/y' }, editable: true,
                   editrules: { required: true },
                   editoptions: {
                       readonly: 'readonly',
                       dataInit: function (el) { $(el).datepicker(); }
                   }
               },
               {
                   name: "Location_Id",
                   index: "Location_Type",
                   width: 0.00001,
                   editable: true,
                   edittype: "select",
                   editrules: { required: true, edithidden: false },
                   editoptions: {value: locations},
                   align: "left", sorttype: "int"
               },
               ],
               // Default sorting
               sortname: "Customer_Name",
               sortorder: "asc",
               width: 840,
               height: 200,
               multiselect: true,
               rowNum: 20,
               rowList: [5, 10, 20, 50, 100],
               pager: jQuery('#pager1'),
               sortorder: "desc",
               viewrecords: true,
               reload:true,
 
               caption: "Customer Data"
           });
 
           jQuery("#list1").jqGrid(
                                       'navGrid',
                                       '#pager1',
                                       { edit: true, add: true, del: true, jqModel: true },
                                       { url: '/customer/Edit', closeAfterEdit: true, reloadAfterSubmit: true, checkOnSubmit: true,checkOnUpdate: true, closeOnEscape: true },
                                       { url: '/customer/Create', closeAfterDelete: true, closeOnEscape: true },
                                       { url: '/customer/Delete', closeAfterAdd: true, reloadAfterSubmit: true, checkOnSubmit: true, closeOnEscape: true },
                                       { multipleSearch: true },
                                       { width: 450, jqModal: true, closeAfterAdd: true }
                                   );
           //jQuery("#list1").trigger("reloadGrid");

           //load data
           getData();
           //grid.setGridParam({ datatype: 'json' });
           //grid.trigger('reloadGrid');
           jQuery("#list1").trigger('reloadGrid');
       });
Posted 30-Apr-13 3:21am
Comments
Prasad Khandekar at 30-Apr-13 8:30am
   
Have you tried looking at the JQGrid demos especially the Edit Row under Live Data Manipulation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 6,769
1 Sergey Alexandrovich Kryukov 6,338
2 DamithSL 5,408
3 Manas Bhardwaj 4,816
4 Maciej Los 4,195


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100