Reputation: 4977
I'm working on a common method to handle AJAX errors for the Kendo Grids in my app. As part of the js function, I'm displaying the error and then cancelling changes for the grid. There's got to be a better way to get the ID for the grid than what I'm doing below - it just feels like a hack to me (even though it does work in my tests). Does anyone have a better way to handle this?
// common kendo grid ajax error handler
function kendoGridAjaxErrorHandler(result) {
var msg = result.xhr.status + ' ' + result.xhr.statusText + '\n' + result.xhr.responseText;
alert(msg);
var id = result.sender.options.table[0].parentNode.parentNode.id;
$('#' + id).data('kendoGrid').cancelChanges();
};
Upvotes: 1
Views: 1623
Reputation: 21
I faced same problem but after spending half an hour i found solution.
You can get Grid Element ID by this
e.sender.options.table.parent('div')[0].id
Upvotes: 1
Reputation: 30661
The error event is exposed by the DataSource and not the grid. As a result you cannot get the grid itself within the error handler. If possible you can try distinguishing the grid based on some data source option e.g. read URL:
function kendoGridAjaxErrorHandler(result) {
var dataSource = this;
var read = dataSource.options.transport.read.url;
if (readUrl == "/Customers/Read") {
// the customers grid
} else {
// other grid
}
}
Upvotes: 1
Reputation: 2385
Have you tried something like $(result.sender.element).attr("id");
?
Upvotes: 0