简体   繁体   English

剑道网格关键和求和列

[英]kendo grid keyup and sum column

Hi i am beginner for kendo grid. 嗨,我是剑道网格的初学者。 When in edit mode, once I keyup the original price and tax amount, I want to sum the final price immediately . 在编辑模式下,一旦我键入了原始价格和税额,我想立即求和最终价格。 Please see my code at below 请在下面查看我的代码

       <div class="panel-body">
                <div id="productRobPrice-grid"></div>

                <script>
                    var record = 0;
                    $(document).ready(function () {
                        $("#productRobPrice-grid").kendoGrid({
                            dataSource: {
                                type: "json",
                                transport: {
                                    create: {
                                        url: "@Html.Raw(Url.Action("ProductRobPriceAdd", "Product"))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    },
                                    read: {
                                        url: "@Html.Raw(Url.Action("ProductRobPriceList", "Product", new {productId = Model.Id}))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    },
                                    update: {
                                        url: "@Html.Raw(Url.Action("ProductPictureUpdate", "Product"))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    },
                                    destroy: {
                                        url: "@Html.Raw(Url.Action("ProductPictureDelete", "Product"))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    }
                                },
                                schema: {
                                    data: "Data",
                                    total: "Total",
                                    errors: "Errors",
                                    model: {
                                        id: "Id",
                                        fields: {
                                            OriginalPrice: {
                                                type: "number", validation: { required: true, min: 1 },
                                            },
                                            Tax: {
                                                type: "number", validation: { required: true, min: 1 },
                                                defaultValue: 6.00
                                            },
                                            FinalPrice: { type: "number", validation: { required: true, min: 1 } },
                                            QuantityFrom: { type: "number", validation: { required: true, min: 1 } },
                                            QuantityTill: { type: "number", validation: { required: true, min: 1 } },
                                            Avalaible: { type: "boolean", defaultValue: true },
                                            AvalaibleQuantity: { type: "number" },


                                        }
                                    }
                                },
                                requestEnd: function (e) {
                                    if (e.type == "update") {
                                        this.read();
                                    }
                                },
                                error: function (e) {
                                    display_kendoui_grid_error(e);
                                    // Cancel the changes
                                    this.cancelChanges();
                                },
                                serverPaging: true,
                                serverFiltering: true,
                                serverSorting: true
                            },
                            pageable: {
                                refresh: true,
                                numeric: false,
                                previousNext: false,
                                info: false,
                                @Html.Partial("_GridPagerMessages")
                            },
                            editable: {
                                confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                mode: "inline"
                            },
                            scrollable: false,
                            toolbar: [{ name: "create", text: "@T("Admin.Common.AddNewRecord")" }],
                            columns: [



                          {
                              field: "OriginalPrice",
                              template: "<strong>#: OriginalPrice # </strong>"
  },

                          {
                              field: "Tax",

                              title: "@T("Admin.Catalog.Products.RobSale.Fields.Tax")",

                          },

                          {
                              field: "FinalPrice",
                              format: "{0:c}",
                              title: "@T("Admin.Catalog.Products.RobSale.Fields.FinalPrice")",

                          },


                          {
                              field: "QuantityFrom",
                              format: "{0:d}",
                              title: "@T("Admin.Catalog.Products.RobSale.Fields.QuantityFrom")",

                          },


                          {
                              field: "QuantityTill",

                              title: "@T("Admin.Catalog.Products.RobSale.Fields.QuantityTill")",

                          },
                          {
                              field: "Avalaible",

                              title: "@T("Admin.Catalog.Products.RobSale.Fields.Avalaible")",

                          },






                            {
                                command: [
                                {
                                    name: "edit",
                                    text: {
                                        edit: "@T("Admin.Common.Edit")",
                                        update: "@T("Admin.Common.Update")",
                                        cancel: "@T("Admin.Common.Cancel")"
                                    }
                                }, {
                                    name: "destroy",
                                    text: "@T("Admin.Common.Delete")"
                                }
                                ],
                                width: 200
                            }
                            ]
                        });
                    });
                </script>
            </div>

But currently got one problem, the original price textbox keyup seem like not able to fire . 但是目前有一个问题, 原始价格文本框快捷键似乎无法启动。 Please give some guideline. 请提供一些指导。 TQ TQ

To attach a function to the keyup event you need to create custom editor function . 要将功能附加到keyup事件,您需要创建自定义编辑器功能

<div id="grid"></div>
<script>
    $("#grid").kendoGrid({
        columns: [{
                field: "name"
            }, {
                field: "price",
                editor: function(container, options) {
                    // create an input element
                    var input = $("<input/>");
                    // set its name to the field to which the column is bound ('name' in this case)
                    input.attr("name", options.field);
                    input.keyup(function() {
                        alert("key up");
                    });
                    // append it to the container
                    input.appendTo(container);
                    // initialize a Kendo UI AutoComplete
                    input.kendoNumericTextBox();
                }
            },
            {
                command: "edit"
            }
        ],
        editable: true,
        dataSource: [{
            name: "Jane Doe",
            price: 5
        }, {
            name: "John Doe",
            price: 10
        }],
        editable: {
            mode: "inline"
        }
    });
</script>

But I think you probably need something like this . 但我认为你可能需要像这样 An aggregate function that will recalculate its value on change. 一个聚合函数,将在更改时重新计算其值。 Not as immediate as keyup but should work for you. 不像keyup那么直接,但是应该为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM