1

I'm writing a generic error handler for all of the Kendo Grids. I need to get that source Grid to prevent its default behavior in saving data. In the handler, you can access the source's DataSouce by args.sender. How can I access the Kendo Grid from that DataSouce?

The only approach I found was this suggestion, searching through all grids, and the handler looks like below, can you suggest anything better and more efficient?

function genericErrorHandler(args) {
    if (args.errors) {
        $('.k-grid').each(function () {
            var grid = $(this).data('kendoGrid');
            if (grid.dataSource == args.sender) {
                alert('found!');
            }
        })
    }
}
Community
  • 1
  • 1
Akbari
  • 2,369
  • 7
  • 45
  • 85

1 Answers1

1

There is no API to get Grid object from data source, but there is many approach beside that.

You can create generic grid's edit event and storing in global scope variable which grid's ID was triggered that event. I prefer to do this rather than compare mutable data source.

var window.currentGrid = "";

function onGenericGridEdit(e) {
    window.currentGrid = e.sender;
}

If in some cases you need to make custom edit function, just call your generic edit function in the end of the code.

function onCustomGridEdit(e) {

   // call generic function to store
   onGenericGridEdit(e);
}
Dion Dirza
  • 2,575
  • 2
  • 17
  • 21