2013-11-25 70 views
1

我想做的事情在我的劍道電網的值之和來形成其總計,總和劍道價值電網

對於我使用的是劍道電網一樣,

@(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") 
          ) 
       ) 

的情況是什麼像這樣:: enter image description here

我想在「總計」中顯示值的總和取決於那裏的變化, 怎麼辦?請幫助我。

+0

使用劍道電網aggregates..http://demos.kendoui.c​​om/web/grid/aggregates.html –

+0

但合計是使用了我的方案特定列 和彙總我想總的所有列的求和。 – Rahul

+0

我想你需要行的總和(不是列)。所以'Sum = Total = SUM(Nett,Tax,GST_VAT ...)'。如果是這種情況,您可以從控制器進行求和。 – Haritha

回答

0

最後我得到了,我用我的方案的東西,&其做人工使用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; 

    }); 

如果有任何新的解決方案,然後請人建議,我會嘗試實施,在我的應用程序。

1

你可以用骨料如本演示:http://demos.kendoui.com/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(); 
     }) 
+0

是的,我知道這個例子,但我的場景是不同的, 請在我的場景中建議我,我應該在上面的代碼中做什麼? – Rahul

1

我想你需要summation of each row。你可以在你的控制器中做到這一點。

Total = Nett + Tax + GST_VAT... 

或者在視圖模型

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

如果你想每一列的總和,使用聚合如Atanas Korchev描述。

0

在我看來,鑑於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的文檔here