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