簡體   English   中英

劍道網格中的值總和

[英]Sum of Values in Kendo Grid

我想對“我的劍道網格”中的值求和以形成總計,

為此,我使用Kendo Grid Like,

 @(Html.Kendo().Grid<Invoice.Models.ViewModels.SupplementViewModel>()
                        .Name("Supplement")
                        .TableHtmlAttributes(new { style = "height:20px; " })
                        .Columns(columns =>
                        {
                            columns.Bound(p => p.SupplementID).Hidden(true);

                            columns.Bound(p => p.Description).Title("Description").Width(15);

                            columns.Bound(p => p.Nett).Title("Nett").Width(15).HtmlAttributes(new { @class="Currency"});
                            columns.Bound(p => p.Tax).Title("Tax").Width(15).HtmlAttributes(new { @class = "Currency" });
                            columns.Bound(p => p.GST_VAT).Title("GST_VAT").Width(15).HtmlAttributes(new { @class = "Currency" });
                            columns.Bound(p => p.ServiceTax).Title("ServiceTax").Width(15).HtmlAttributes(new { @class = "Currency" });
                            columns.Bound(p => p.ServiceFee).Title("ServiceFee").Width(15).HtmlAttributes(new { @class = "Currency" });
                            columns.Bound(p => p.Total).Title("Total").Width(15).HtmlAttributes(new { @class = "Currency" });


                        })
                        .Editable(editable => editable.Mode(GridEditMode.InCell))
                        .Navigatable()
                        .Sortable()
                        .Scrollable(scr => scr.Height(200))
                        .Scrollable()
                        .DataSource(dataSource => dataSource
                            .Ajax()
                            .Batch(true)
                            .ServerOperation(false)
                            .Events(events => events.Error("error_handler"))
                            .Model(model =>{
                                model.Id(p => p.ProductTypeCode);
                            })
                            .Create("Editing_Create", "Grid")

                            .Update("Editing_Update", "Grid")
                            .Destroy("Editing_Destroy", "Grid")
                            )
                )

場景是這樣的: 在此處輸入圖片說明

我想在“總計”中顯示值的總和取決於那里的變化,該怎么做? 請幫我。

您可以使用本演示中所示的聚合: http : //demos.kendoui.c​​om/web/grid/aggregates.html

有兩種聚合-一種是在分組過程中應用的,另一種是應用於整個網格的。 這是定義后者的方法:

 .DataSource(dataSource => dataSource
        .Ajax()
        .Aggregates(aggregates =>
        {
            aggregates.Add(p => p.UnitsInStock).Min().Max().Count();
            aggregates.Add(p => p.UnitsOnOrder).Average();
            aggregates.Add(p => p.ProductName).Count();
            aggregates.Add(p => p.UnitPrice).Sum();
        })

我猜你需要summation of each rowsummation of each row 您可以在控制器中執行此操作。

Total = Nett + Tax + GST_VAT...

或在視圖模型中

public int Total
{
    get
    {
        return this.Nett + this.Tax;
    }
}

如果要匯總每一列,請使用Atanas Korchev所述的Atanas Korchev

最終,我得到了我在場景中使用的東西,並使用javascript:手動完成了它:

  $("#Supplement").on('change', '.Currency > input[type="text"]', function () {
        var row = $(this).closest("tr");
        var temp = $(this).val();

        var nett = parseFloat(row.find('input')[2].value);
        var tax = parseFloat(row.find('input')[3].value);
        var gst_vat = parseFloat(row.find('input')[4].value);
        var servicetax = parseFloat(row.find('input')[5].value);
        var servicefee = parseFloat(row.find('input')[6].value);
        var total = nett + tax + gst_vat + servicetax + servicefee;
        row.find('.TotalCurrency ')[0].textContent = total;

    });

如果有人有任何新的解決方案,請提出建議,我將嘗試在我的應用程序中實現它。

在我看來,鑒於需要對Total進行客戶端更新,您的解決方案是可行的。

我建議您不要直接獲取或更新單元格數據(例如var tax = parseFloat(row.find('input')[3].value );

而是使用網格客戶端API獲取值。 即:

var grid = $("#grid").data("kendoGrid");
var row = $(this).closest("tr");
var data = grid.dataItem(row);
tax = data.tax;

在此處查看dataItem的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM