使用kendo网格中的动态下拉列表进行内联编辑

时间:2014-07-07 05:01:26

标签: javascript jquery kendo-grid nopcommerce

我一直在尝试使用kendo网格使nopCommerce中的规范属性可以内联编辑。

如果您不是一个nop人,只需考虑一个现有的剑道编辑网格,该网格有一个不可编辑的列,我想使用下拉列表使该列可编辑。由于我编辑的数据的性质,每行的下拉选项会有所不同。

当前状态是未处于编辑模式时列正确显示。在编辑模式下,它显示正确的值,但是没有选择任何值。更新似乎没有回发到服务器,有时(取决于我尝试的)导致kendo内部的javascript错误。

我对剑道几乎一无所知,需要通过此下拉列表进行更新。下面是一些代码片段(整个事情太长了):

grid = $("#specificationattributes-grid").kendoGrid({
                    dataSource: {
                        type: "json",
                        transport: {
                            read: {
                                url: "@Html.Raw(Url.Action("ProductSpecAttrList", "Product", new { productId = Model.Id }))",
                                type: "POST",
                                dataType: "json"
                            },
                            update: {
                                url: "@Html.Raw(Url.Action("ProductSpecAttrUpdate", "Product"))",
                                type: "POST",
                                dataType: "json"
                            },
                            destroy: {
                                url: "@Html.Raw(Url.Action("ProductSpecAttrDelete", "Product"))",
                                type: "POST",
                                dataType: "json"
                            }
                        },
                        schema: {
                            data: "Data",
                            total: "Total",
                            errors: "Errors",
                            model: {
                                id: "Id",
                                fields: {
                                    //ProductId: { editable: false, type: "number" },
                                    SpecificationAttributeName: { editable: false, type: "string" },
                                    SpecificationAttributeOptionId: { editable: true, type: "number" },
                                    CustomValue: { editable: true, type: "string" },
                                    AllowFiltering: { editable: true, type: "boolean" },
                                    ShowOnProductPage: { editable: true, type: "boolean" },
                                    DisplayOrder: { editable: true, type: "number" },
                                    Id: { editable: false, type: "number" }
                                }
                            }
                        },
.......................
columns: [{
                            field: "SpecificationAttributeName",
                            title: "@T("Admin.Catalog.Products.SpecificationAttributes.Fields.SpecificationAttribute")",
                            width: 200
                        }, {
                            field: "SpecificationAttributeOptionId",
                            title: "@T("Admin.Catalog.Products.SpecificationAttributes.Fields.SpecificationAttributeOption")",
                            width: 200,
                            editor: renderDropDown, template: "#= getOptionValue(SpecificationAttributeName, SpecificationAttributeOptionId) #"
                        }, 

方法" getOptionValue"不包括在内,但基本上在不处于编辑模式时将值转换为易于显示的标签。 " renderDropDown"创建一个包含当前行的正确选项的kendoDropDownList。

1 个答案:

答案 0 :(得分:1)

如果您返回id,值对,例如

"{\"SpecificationAttributeOptionId\":\"0\",\"SpecificationAttributeName\":\"XYZ\"},
 {\"SpecificationAttributeOptionId\":\"1\",\"SpecificationAttributeName\":\"ABC\"}"

然后您需要指定dataTextField,dataValueField。否则,如果您返回List string,如下所示,那么您不需要指定dataTextField,dataValueField和kendo将负责其余的工作。

"{\"SpecificationAttributeName\":\"XYZ\"},
 {\"SpecificationAttributeName\":\"ABC\"}"

希望这有帮助。

$("#SpecificationAttributeOptionId").kendoDropDownList({
        dataTextField: "SpecificationAttributeName",
        dataValueField: "SpecificationAttributeOptionId",
        dataSource: {
            transport: {
                read: {
                    url: "/ControllerName/GetDropDownValueFunction",
                    type: "POST",
                    contentType: "application/json",
                    dataType: "json"
                }
            }
        },
        height: 100
    });
相关问题