Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Grid/DataSource - Global Error Handling?

I've currently inherited an application which has numerous Kendo grids (and other controls) throughout, and I'm trying to fix an error which keeps cropping up now and again - specifically when the user is no longer authenticated.

I know what the solution is for a single instance of the control - return a flag to indicate authentication failed, and then detect this in the error handler and perform the authentication.

The problem is am I really going to have to handle this for every instance of a Kendo control I have? Is there not a global error handler I can hook into? Either for the data source itself (as I know this is used for all Kendo control data loading), or for the Grid specificially. I don't mind either way - just which one is a hook.

This would be a more straighforward short term solution than refactoring everything to specific error handlers, etc.

like image 743
stevehayter Avatar asked Mar 19 '13 12:03

stevehayter


2 Answers

I assume you can attach a global error handler to $.ajax, which is used by the DataSource, you can check how to do it here: http://api.jquery.com/category/ajax/global-ajax-event-handlers/

Or, you can take advanttage of that the configuration that is done in the DataSource is passed directly to the $.ajax: http://docs.kendoui.com/api/framework/datasource#configuration-transport.read-ObjectStringFunction

like image 96
Botis Avatar answered Oct 18 '22 11:10

Botis


For reference, someone from Telerik has provided a solution using just the DataSource. I haven't tested it, but I prefer the accepted answer above as it hooked into all Ajax on the site - not just ones that utilise the Kendo DataSource.

http://www.kendoui.com/forums/mvc/grid/global-error-handler-for-numerous-grids.aspx

like image 44
stevehayter Avatar answered Oct 18 '22 12:10

stevehayter