kendo grid delete按钮不会触发删除功能

时间:2015-06-30 12:00:56

标签: javascript post kendo-ui

这是我的网格:

$("#category-gridview").kendoGrid({
     dataSource: {
         type: "json",
         transport: {
             read: {
                 url: function (options) {
                     return '/Product/GetCategories?id=' + $("#selectedProductId").val() + '&company=' + $("#company-dropdown").val() + '&language=' + $("#country-dropdown").val();
                 },
                 dataType: "json",
                 type: "POST"
             },
             destroy: {
                 url: '/Product/DeleteProductCategory',
                 dataType: "json",
                 type: "POST",
                 contentType: "application/json"
             },
             parameterMap: function (options, operation) {
                 console.log("HÄÄR");
                 console.log(options);
                 if (operation !== "read" && options.models) {
                     return JSON.stringify({
                         category: options
                     });
                 }
             }
         },
         schema: {
             model: {
                 fields: {
                     id: {
                         type: "string"
                     },
                     name: {
                         type: "string"
                     },
                 }
             }
         },
     },
     columns: [{
         field: "id",
         hidden: true

     }, {
         field: "name",
         title: "Category",
         width: "30px"
     }, {
         command: "destroy",
         title: " ",
         width: 15
     }],
     editable: false,
 });

以某种方式读取功能按预期工作,但当我按下删除按钮时,我甚至无法访问我的参数映射功能。 当我查看chrome控制台时,没有请求发送到我的控制器。

这是我的控制器方法:

[HttpPost]
public JsonResult DeleteProductCategory(CategoryResponse category)
{
    return Json(category);
}

2 个答案:

答案 0 :(得分:0)

Let me try to answer, but to note that i change your transport and the column setting to match the field using kendo because obviously i can't use yours. Similar to this

transport: {
             read: {
                 url: "http://demos.telerik.com/kendo-ui/service/products",
                 dataType: "jsonp"
             },
             destroy: {
                 url: "http://demos.telerik.com/kendo-ui/service/products/destroy",
                    dataType: "jsonp"
             },
             parameterMap: function(options, operation) {
                    if (operation !== "read" && options.models) {
                        return {models: kendo.stringify(options.models)};
                    }
                }
}, 
  • At first glance i notice you use "POST" on read and delete call, actually you don't need them?

But then you said that you couldn't reach the parametermap, i came to think of

  • You set editable : false, how can you edit it if you set it to false? you should make it to editable : true(note: also you can try to set it to false and then you can see the delete function will not work)

DEMO

答案 1 :(得分:0)

而不是字符串{param:value}只需为参数stringify(options.models)字符串化值category

parameterMap: function(options, operation) {
                                if (operation !== "read" && options.models) {
                                    return { category: kendo.stringify(options.models) };
                                }
                            }