I am trying to make a reusable error handling function like showed in the examples:
How can I reference the grid by name, so I can put this function inside my shared layout page and be able to cancel the changes of any grid ?
11 Answers, 1 is accepted
The error event is raised by the data source (e.sender and "this" are the data source instance) which makes getting the grid name hard. A possible workaround is to use a closure when defining the error handler. Something like this:
Then use it like this:
Please try with the below code snippet.
Sorry, but the e.sender.options.table maybe null, and e.sender.element property is/maybe not exist too.
There have no way to get the Grid's name in error event.
The following syntax allows the developer to pass the name of the Grid as second argument to the error handler:
Hope this helps.
If this is a case of grid hierarchy scenario and it is a detail grid with a dynamic name, you could pass the grid name as additional data and return it to the client along with the errors.
Let me know in case you need anything else or if I have misunderstood the scenario.
I know this is old, but for anyone finding this now, the sending grid's id is accessible with e.sender.element.id
The Kendo UI Grid only displays the data it is not aware that the data source has thrown an error. The error event is thrown by the DataSource widget and e.sender is the data source instance which throws the error, not the grid.
The proposed handler throws an error because e.sender does not have an element:
That's a good point, sorry about that, got confused since I'm definitely using element for the DataBound event, but that's a grid-level event, not a DataSource event.
I'm using the MVC grid and the easiest approach I found was as was suggested, to send the grid Id as a parameter to the error handler.