自动计算剑道网格列

时间:2015-04-13 07:40:22

标签: model-view-controller kendo-ui kendo-grid

我想在客户端自动计算Kendo Grid Column。我的代码是

   @(Html.Kendo().Grid(Model)
                .Name("VATGrid")
                .Columns(columns =>
                {

                    columns.Bound(p => p.BaseAmount);

                    columns.Bound(x => x.Unit);
                    columns.Bound(p => p.VATPercentage);

                    columns.Bound(p => p.VATAmount)
                            .HeaderHtmlAttributes(new { title = "VAT Amount" })
                            .HtmlAttributes(new { style = "text-align:right" })
                            .Title("VAT Amount")
                        .ClientTemplate(
                                        "#= VATAmount=kendo.toString(BaseAmount*Unit*VATPercentage, 'n2')#" +
                                        "<input type='hidden' class='VATAmount'  value='#=kendo.toString(BaseAmount*Unit*VATPercentage, 'n4')#' />");

                                          })

                .Editable(editable => editable.Mode(GridEditMode.InCell))

                .DataSource(dataSource => dataSource
                    .Ajax()
                    .Batch(true)
                    .ServerOperation(false)
                    .Model(model =>
                                    {
                                        model.Id(p => p.DocumentVATID);
                                        model.Field(x => x.CompanyVATType).Editable(false);
                                        model.Field(x => x.VATPercentage).Editable(false);
                                        model.Field(x => x.VATType).Editable(false);
                                        model.Field(x => x.BaseAmount).DefaultValue(0);
                                        model.Field(x => x.Unit).DefaultValue(0);
                                    })
                    )

我可以获得自动计算值,但点击Grid Cell后。 我想显示变化本身的计算值

1 个答案:

答案 0 :(得分:0)

这样的东西?

    @(Html.Kendo().Grid(Model)
    .Name("VATGrid")
    .Columns(columns =>
    {

        columns.Bound(p => p.BaseAmount);

        columns.Bound(x => x.Unit);
        columns.Bound(p => p.VATPercentage);

        columns.Bound(p => p.VATAmount)
                .HeaderHtmlAttributes(new { title = "VAT Amount" })
                .HtmlAttributes(new { style = "text-align:right" })
                .Title("VAT Amount")
            //.ClientTemplate(
                            //"#= VATAmount=kendo.toString(BaseAmount*Unit*VATPercentage, 'n2')#" +
                            //"<input type='hidden' class='VATAmount'  value='#=kendo.toString(BaseAmount*Unit*VATPercentage, 'n4')#' />");
                            //})
            .ClientTemplate(
                            "<span id="vatId">#= VATAmount=kendo.toString(BaseAmount*Unit*VATPercentage, 'n2')#</span>" +
                            "<input type='hidden' class='VATAmount'  value='#=kendo.toString(BaseAmount*Unit*VATPercentage, 'n4')#' />");
                            })
    //put span tag around the clienttemplate above
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Events(e => e.Change("onProductChange"))  //add this event listener
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Model(model =>
                        {
                            model.Id(p => p.DocumentVATID);
                            model.Field(x => x.CompanyVATType).Editable(false);
                            model.Field(x => x.VATPercentage).Editable(false);
                            model.Field(x => x.VATType).Editable(false);
                            model.Field(x => x.BaseAmount).DefaultValue(0);
                            model.Field(x => x.Unit).DefaultValue(0);
                        })
        )

<script type="text/javascript">
    function onChange(e) {
        var selected = $.map(this.select(), function (item) {
            return $(item).text();
        });
        console.log("Selected: " + selected.length + " item(s), [" + selected.join(", ") + "]");
        //TODO: calculate your data and use calc variables below
        var calc1 = 0;
        var calc2 = 0;
        $("#vatId").text(calc);
        $(".VATAmount").val(calc2);  //or something like that, but you get the grip
    }
</script>

也许我误解了你的问题,但听起来好像你想在每次选择一个单元格时计算你的footertemplate中的数据。