Kendo Grid - 在Firefox中,在save事件中触发警报会导致页面重新加载

时间:2013-04-05 20:42:42

标签: kendo-ui kendo-grid

我想知道是否有人见过这个。我有一个kendo网格,在save事件中,我想做一些验证。基本上是为了确保旧值之间的新值差异小于或等于余额。

因此,如果它大于余额,我会触发警报并阻止默认。但是,显示警报会导致页面在FireFox中重新加载。

这是我的网格:

$("#gridOpenInvoices").kendoGrid({
        autoBind: false,
        dataSource: openInvoicesData,
        scrollable: true,
        sortable: false,
        navigatable: true,
        toolbar: [{name:"save",
                   text:strings.ApplyUpdates},
                  {name: "SplitPayment",
                   text: strings.SplitPayment},
                  {name: "PaidOut",
                   text: strings.PaidOut},
                  {name: "CreateCredit",
                   text: strings.CreditBalance},
                  {name: "UndoAllocation",
                   text: strings.UndoAllocation}],
        columns: [
            {
                field: "CustomerName",
                title: strings.AccountName,
                hidden: true
            },
            {
              field: "OpenTransactionId",
              title: strings.OpenTransaction,
              width:90
            },
            {
              field: "InvoiceNumber"  ,
              title: strings.InvoiceNumber,
              width:65
            },
            {
                field: "GrossSales",
                title: strings.OriginalAmount,
                width: 75,
                format: "{0:c}",
                decimals: 2,
                min: 1,
                value: 0

            },
            {
                field: "Balance",
                title: strings.TransBalance,
                width: 75,
                format: "{0:c}",
                decimals: 2,
                min: 1,
                value: 0

            },
            {
                field: "Date",
                title: strings.Date,
                width:75,
                format: "{0:MM/dd/yy}"

            },
            {
                field: "Age",
                title: strings.Age,
                width:55

            },
            {
                field: "CheckNumber",
                title: strings.CheckNumber,
                width:85
            },
            {
                title: strings.ApplyPayment,
                width:75,
                template: "<input class='k-chk-applied chkbox' type='checkbox' data-bind='source: IsApplied' name='IsApplied' #= IsApplied ? 'checked' : ''#/>",
                attributes:{"class":"tdIsApplied"}
            },
            {
                field:"AppliedAmount",
                title: strings.AppliedAmount,
                format: "{0:c}",
                width: 95,
                attributes: {"class" : "tdAppliedAmount"}
            }],
save: function(e) {
    var model = e.model;
    if (e.values.AppliedAmount != null) {
        var remainingBalance = context.getRemainingBalance();
        var difference = e.values.AppliedAmount - model.AppliedAmount;
        if (remainingBalance >= difference) {
            var balanceCopy = model.BalanceCopy;
            model.Balance = model.GrossSales - e.values.AppliedAmount;
            model.BalanceCopy = model.GrossSales - e.values.AppliedAmount;

            if (model.Balance == 0 && model.IsUncollected) {
                model.IsUncollected = false;
                context.UpdateBalance(balanceCopy, 0, true);
            }
            context.UpdateBalance(model.AppliedAmount, e.values.AppliedAmount, true);
            this.refresh();
            context.showButtons();
        } 
        else {
            alert("The applied amount exceeds the remaining balance");
            e.preventDefault();
        }
    }
}, editable:"incell"});

这似乎只在您编辑应用的金额并按Enter键进行提交时才会发生。知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

解决方案非常简单:不要使用警报。

我在kendoUI Widgets的某些事件中遇到了同样的问题。 如果需要向用户显示内容,请使用kendoWindow,并将其模态属性设置为true。

警报只应用于调试目的,例如console.log。