Reputation: 44
I have a kendo grid with multiple columns and multiple rows. I want the last column to show calculated data. I want to make an AJAX method take ID and get some data from the database and show it in this column (all rows). How can I do that?
var grid = $("#grid").kendoGrid({
dataSource: ds,
columns: [{
field: 'ID',
title: '#',
hidden: true
}, {
title: 'Test',
filterable: false,
width: "130px",
ClientTemplate: "#=MyMethod(ID)#"
}]
}).data("kendoGrid");
function MyMethod(ID) {
var returnData = 0;
$.get('@Url.Action("Action", "Controller")', {
Id: ID
}, function(response) {
returnData = response;
});
return returnData;
}
Upvotes: 0
Views: 1009
Reputation: 6335
I would recommend you don't do that.
The reason I say this is because you would trigger an ajax call for each row and there can be lots of rows which potentially means a long delay before you can show something to the user.
You most likely have one database call to return the data. In that one call, do any calculation required, if it's only a total, the database itself can deal with this in a very fast manner. So do your calculation there, return the calculated field as an extra field in your dataset and then your UI only has to show a field which is already calculated.
It's going to be much quicker and a much better user experience as well.
Upvotes: 1