This is a migrated thread and some comments may be shown as answers.

KendoGrid edit and destroy ajax call

4 Answers 244 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pawan
Top achievements
Rank 1
Pawan asked on 14 Sep 2012, 08:31 AM
Hello,

I'm using KendoGrid to populate the data and also doing CRUD functionality. But my problem is that I'm not able to update/Delete entities  as I'm not able to  make ajax call .

Kindly suggest me where  I'm going  wrong . 


Thanks,



$("#GridTestJS").kendoGrid({
       columns: [{ title: "Fontfamily", field: "Fontfamily" },
              { title: "FontPreviewImage", field: "FontPreviewImage" },
             { command: ["edit", "destroy"], title: " ", width: "210px"}],
       editable: "popup",
       dataSource:
       {
           transport:
          {
              read: { url: "/Test/GetFontDetails" },
              update: { url: "/Test/updateFontDetails",
                  data: {}
              },
              destroy: { url: "/Test/destroyFontDetails" }
          }
       },
       selectable: "row"
   });
 
  public JsonResult GetFontDetails()
       {
           var Allfonts = context.Fonts.ToList();
           return Json(Allfonts, JsonRequestBehavior.AllowGet);
       }
 
       public JsonResult updateFontDetails(Font obj)
       {
           var Allfonts = context.Fonts.ToList();
           return Json(Allfonts, JsonRequestBehavior.AllowGet);
       }
 
       public JsonResult destroyFontDetails(Font obj)
       {
           var Allfonts = context.Fonts.ToList();
           return Json(Allfonts, JsonRequestBehavior.AllowGet);
       }

4 Answers, 1 is accepted

Sort by
0
Pawan
Top achievements
Rank 1
answered on 18 Sep 2012, 07:27 AM
Is there anyone who really knows it and can help me . 
0
Josh
Top achievements
Rank 1
answered on 21 Sep 2012, 01:34 PM
Have you tried putting :

batch:false,


In you datasource control?
0
Pawan
Top achievements
Rank 1
answered on 22 Sep 2012, 01:28 PM
Yes , Even I tried that also... But no gain
0
Michael
Top achievements
Rank 1
answered on 04 Oct 2012, 01:43 PM
I believe you'll need to add a parameter map.

Unfortunately the documentation on this isn't the best, but it's here: http://docs.kendoui.com/api/framework/datasource#transportparametermap-function.  It may be even simpler than what I have, this is just what has worked for for me the past.

$("#GridTestJS").kendoGrid({
       columns: [{ title: "Fontfamily", field: "Fontfamily" },
              { title: "FontPreviewImage", field: "FontPreviewImage" },
             { command: ["edit", "destroy"], title: " ", width: "210px"}],
       editable: "popup",
       dataSource:
       {
          transport:
          {
              read: { url: "/Test/GetFontDetails" },
              update: { url: "/Test/updateFontDetails",
                  data: {}
              },
              destroy: { url: "/Test/destroyFontDetails" },
             parameterMap: function (data, operation) {
              if (operation != "read") {
                var result = {};
                for (var i = 0; i < data.models.length; i++) {
                  var font = data.models[i];
                  for (var member in font) {
                    result["obj[" + i + "]." + member] = font[member];
                  }
                }
                return result;
             }
             return null;
           }
          }
       },
       selectable: "row"         
   });


You may even be able to do something like below.  (return an object with fields the same as are in your Font class and MVC will automatically map these to a font class.

parameterMap: function(options, type) {
          return {
             Fontfamily: options.Fontfamily
          FontPreviewImage: options.FontPreviewImage          
          }
       }

Tags
Grid
Asked by
Pawan
Top achievements
Rank 1
Answers by
Pawan
Top achievements
Rank 1
Josh
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or