简体   繁体   English

如何访问Kendo网格页脚模板值

[英]How to access the kendo grid footer template value

i have developed a web application using kendo tools and asp.net mvc4.. 我已经使用Kendo工具和asp.net mvc4开发了一个Web应用程序。

below is a screenshot of the grid i'm using and i need to get the value of footer under the "Total Stock" column.. according to this, the total value is $74,050.85.. 下面是我正在使用的网格的屏幕截图,我需要在“总计股票”列下获取页脚的值 ..据此,总值为74,050.85美元。

i need to assign this value to a text box or a variable and use it in some where else but there no positive feedback from the online resources.. 我需要将此值分配给文本框或变量,并在其他地方使用它,但在线资源没有积极反馈。

在此处输入图片说明

can somebody please tell me that how to get a value from footer template .. 有人可以告诉我如何从页脚模板中获取价值 ..

i guess you use aggregate function in your kendogrid to calculate Total Stock[so your total $74,050.85..], am i right?? 我猜您在kendogrid中使用了合计函数来计算总库存[因此,您的总计$ 74,050.85 ..],对吗?

if yes than this should be the best answer for your question. 如果是,那么这应该是您问题的最佳答案。 example your kendogrid id = 'gridtotal', and your field that aggregated = total_stock 例如,您的kendogrid id ='gridtotal',而您汇总的字段= total_stock

so if you want to get the total, you just do this 因此,如果您想获得总数,则只需执行此操作

    var total = $("#gridtotal").data().kendoGrid.dataSource.aggregates().total_stock.sum;

here if you want to know more http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-group.aggregates 如果您想了解更多信息,请在这里http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-group.aggregates

Under the grid column definition, add 在网格列定义下,添加

footerAttribute: {"id":"total-stock"}

This will add an id to the cell. 这将为该单元格添加一个ID。 Then you can just use jquery to pull it directly: 然后,您可以使用jquery直接将其拉出:

var totalStock = $("#total-stock").text().split(":")[1]

If you wanted to pull the raw numerical value, you could get it as well by parsing the number out, or you can assign it as an attribute to the cell. 如果要提取原始数值,也可以通过将数字解析出来来获取,也可以将其作为属性分配给单元格。

footerAttribute: {"id":"total-stock", "data-value": sum }

Then reference it later 然后再参考

var totalStock = $("#total-stock").data("value")

You can get the footer aggregate values (such as total) by setting a footerTemplate . 您可以通过设置footerTemplate获得页脚聚合值(例如合计)。 That footer template can execute arbitrary code such as updating a textbox value. 该页脚模板可以执行任意代码,例如更新文本框值。

The other option is to use jQuery to get the text of the footer: 另一种选择是使用jQuery获取页脚的文本:

var totalText = $("#grid .k-footer-template").text();

Sanzy, 桑兹

Have you figured out setting the value of the footer template total? 您是否已确定设置页脚模板总计的值?

This is what I used. 这就是我用的。

var totalWeight = 0;
var theGridData = $(gridSelector).data("kendoGrid").dataSource.data();
$(theGridData).each(function (index, item) {
    totalWeight += item.Weight;
});
$('#total-stock').text("Total: " + totalWeight); 

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM