How to access the kendo grid footer template value

时间秒杀一切 提交于 2021-02-08 06:17:19

问题


i have developed a web application using kendo tools and asp.net mvc4..

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..

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..

enter image description here

can somebody please tell me that how to get a value from footer template..


回答1:


You can get the footer aggregate values (such as total) by setting a 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:

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



回答2:


i guess you use aggregate function in your kendogrid to calculate Total Stock[so your total $74,050.85..], am i right??

if yes than this should be the best answer for your question. example your kendogrid id = 'gridtotal', and your field that aggregated = 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




回答3:


Under the grid column definition, add

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

This will add an id to the cell. Then you can just use jquery to pull it directly:

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



回答4:


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.



来源:https://stackoverflow.com/questions/18144993/how-to-access-the-kendo-grid-footer-template-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!