Search code examples
asp.net-mvcjqgrid

Edit row always cal function in Controller


Why save row in jqGrid always call to 1 function test in Controller? I using jqgrid 4.6.0

In Controller i create a view Method like this

public class TesMasterDataController : Controller
{
     public ActionResult test()
     {
       // debug here
       return View();
     }
 }

Create any grid load for any data View by JQgrid.

Open any row for edit on onCellSelect:

onCellSelect: function (rowid) {
              $("#" + gridId).jqGrid("editRow", rowid, false, "clientArray");
              setTimeout(jQuery("#" + gridId).saveRow(rowid, {
                 successfunc: function () {
                   return true;
                }
               }, "clientArray"), 300);
            }

Debug at controller Test method you can see, function saveRow always call to it, although I has been set url null?


Solution

  • The code of onCellSelect callback is very strange because of many things, but your main problem in the wrong usage of saveRow. Currently you use it in the following form

    .saveRow(rowid, {
               successfunc: function () {
                   return true;
               }
           }, "clientArray");
    

    The method saveRow can be used in one from the following forms: either

    .saveRow(rowid, {
               url: "clientArray",
               successfunc: function () {
                   return true;
               }
           });
    

    or

    .saveRow(rowid,
             function () {
                 return true;
             },
             "clientArray");
    

    Additionally, it's recommended don't use retro version 4.6.0, which is more as 3.5 years old. There are two main forks of jqGrid: "free jqGrid", which I develop and which can be used for free under the same licenses like jqGrid 4.6, and commercial "Guriddo jqGrid JS", which develop Tony Tomov. I recommend you to choose one from the products and update jqGrid 4.6 to the latest version of the corresponding product. The current version of free jqGrid is 4.15.2. You can load it directly from CDN (see the wiki article). To test it you will need just change 3 lines of your code: the URLs from which you load jqGrid css/js files. Free jqGrid is compatible with jqGrid 4.6, but it supports a lot of new features. You can look at here first of all.