在网格中具有下拉菜单的InCell编辑不会保存更改以进行批量编辑

时间:2019-07-02 12:58:56

标签: c# .net-core kendo-grid kendo-dropdown

我必须使用inCell编辑进行Kendo grid的操作,其中一列必须是下拉菜单。当单元格不在编辑模式时,它将显示模型的名称。当我进入该单元格的编辑模式时,当我选择所需的值时,该下拉列表会像应该的那样填充,但是当我单击远离正在编辑的单元格时,显示值仍然是旧值而不是所选值。但是,当我想再次编辑它时,将显示正确的值。我制作了一张gif显示我的问题:Here

我尝试过的事情就像在网格的列部分中使用bound和foreignKey一样(两者都发生了相同的事情),当我通过javascript退出单元格编辑时,添加了一个事件来更改所需文本的单元格值( .Events(ev => ev.Save(@"function(e){setTimeout(bindOnClose())}"))),然后在下拉列表中将data_value_primitive设置为true。

这是我的代码: 视图

@(Html.Kendo().Grid<MPAdminCORE.Models.ProductCategory>()
                            .Name("grid").ToolBar(toolbar =>
                            {
                                toolbar.Save().SaveText("Shrani").CancelText("Prekliči"); // The "save" command saves the changed data items
                                toolbar.Excel().Text("Excel");
                            })
                            .Excel(excel => excel
                                .FileName("NerazvrščeniArtikli.xlsx")
                                .Filterable(true)
                            )
                            .Selectable()
                            .Editable(editable => editable.Mode(GridEditMode.InCell)) // Use inline editing mode
                            .DataSource(dataSource =>
                                dataSource.Ajax()
                                .Model(model =>
                                {
                                    model.Id(x => x.Id); // Specify the property which is the unique identifier of the model
                                    model.Field(x => x.Id).Editable(false); // Make the ProductID property not editable
                                    model.Field(x => x.Product.Name).Editable(false);
                                    model.Field(x => x.Product.Sku).Editable(false);
                                    model.Field(x => x.Product.FullDescription).Editable(false);
                                    model.Field(x => x.Product.VendorId).Editable(false);
                                    model.Field(x => x.CategoryId);
                                    model.Field(x => x.Category).DefaultValue(ViewData["NopProductCategories"] as CategoryViewModel);
                                })
                                .ServerOperation(false)
                                .Events(events =>
                                {
                                    events.RequestEnd("onRequestEnd");
                                })
                                .Read(read => read.Action("ImpProducts_Read", "ImpUncategorisedProduct")
                                .Data("vendoridReadData"))
                                .Update(create => create.Action("EditingCustom_Update", "ImpUncategorisedProduct").Data("TESTupdateData"))
                                .Destroy("DeleteUncategorisedProductCategory", "ImpUncategorisedProduct").PageSize(30)
                            )  // Action invoked when the grid needs data
                            .Columns(columns =>
                            {
                                columns.Bound(impproduct => impproduct.Product.Sku).HtmlAttributes(new { id = "SkuCode" });
                                columns.Bound(impproduct => impproduct.Product.Name);
                                columns.Bound(impproduct => impproduct.Product.FullDescription).HtmlAttributes(new { style = "white-space: nowrap; max-width: 100px;" });
                                columns.Bound(impproduct => impproduct.Product.VendorId).Width(120).Title("Id dobavitelja");
                                columns.Bound(impproduct => impproduct.Category).ClientTemplate("#=Category.CategoryName#");
                                columns.ForeignKey(impproduct => impproduct.CategoryId, (System.Collections.IEnumerable)ViewData["NopProductCategories"], "Id", "Name").EditorTemplateName("NopProductCategoryEditor")
                                    .Title("Kategorije NOP produkta");
                            })
                            .Pageable(pageable => pageable
                                .Refresh(true)
                                .PageSizes(true)
                                .PageSizes(new[] { 30, 50, 100 })
                                .Messages(messages => messages.Display("{0} - {1} od {2} vrstic"))
                                .Messages(messages => messages.ItemsPerPage("vrstic na stran"))
                                .Messages(messages => messages.Empty("Ni vrstic")) // Enable paging
                            ) // Enable paging
                            .AutoBind(false)

我的填充viewData的控制器方法:

ICategoryService cat = EngineContext.Current.Resolve<ICategoryService>();
            var cats = cat.GetAllCategories(showHidden: true);
            ViewData["NopProductCategories"] = cats.Select(c => new { Id = c.Id, Name = cat.GetFormattedBreadCrumb(c) });

我的模特:

public partial class ProductCategory
    {
        //other fields
        ...

        [UIHint("NopProductCategoryEditor")]
        public virtual CategoryViewModel Category { get; set; }

    }
    public class CategoryViewModel
    {
        [Key]
        public int CategoryID { get; set; }

        public string CategoryName { get; set; }
    }

我的下拉菜单(NopProductCategoryEditor.cshtml):

        .HtmlAttributes(new { data_value_primitive = "true" })
        .Name("Category") // Name of the widget should be the same as the name of the property
        .DataValueField("Id") // The value of the dropdown is taken from the property
        .DataTextField("Name") // The text of the items is taken from the property
        .BindTo((System.Collections.IEnumerable)ViewData["NopProductCategories"]) // A list of all which is populated in the controller
)

我想发生的事情是它将新选择的值保存在单元格中,直到用户决定单击“保存”或“取消”。 Example

0 个答案:

没有答案