2017-04-02 77 views
0

嗨,我是剑道网的初学者。在编辑模式下,一旦我的键入原来的价格和税额,我想马上结束最终价格。请参阅我的代码以低于kendo grid keyup and sum列

 <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> 

,但目前有一个问题,原价文本 KEYUP似乎无法开火。请给一些指导。 TQ

+0

您想要立即更新总价,因为原始价格已被编辑?你看过在数据源中设置聚合吗?他们将在保存时更新总数。 – Padhraic

+0

可以举个例子吗? – user998405

回答

0

要将功能附加到keyup事件,您需要创建custom editor function

<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> 

但我想你可能需要像this之类的东西。一个聚合函数,将重新计算其变化值。不如keyup立即,但应该为你工作。