This may sound like a stupid question, but as far as I understand, we always need to use the data() method to get the widget object which we can use to call its methods upon.
This seems to be counter-productive in terms of object chaining. Is there a method available that allows me to go back to the initialilly selected object? I'm a hug fan of chaining , and usually my code looks like this:
$(
'object-selector'
)
.method1()
.method2()
.method3();
when I need to execute a method on a widget, I am not sure how this would work:
$(
'object-selector'
)
.data(
"kendoGrid"
)
.someGridMethod();
--> I seem to be unable to go back to the selected object to add other methods. Am I missing something? Why aren't the methods simply exposed on the initial object? It just doesn't seem to be making any sense to me to be honest.
8 Answers, 1 is accepted
I think most jQuery plugins are implemented that way in order not to extend the jQuery.fn object with widget specific methods. jQuery.fn is extended with only one method per plugin - kendoGrid(), kendoMenu etc.
Regards,Atanas Korchev
the Telerik team

I disagree. We use a LOT of jQuery plugins, and this is the very first one working like this. Look at jQueryUI - the framework you like to measure yourself against (rightfully so!) - it simply extends the object with widget specific objects.
If you develop in whatever language you develop in, once you inherit from an (abstract) class, you get the parent methods, but extend the object with your own methods. If you worry about overriding methods, why don't you just prefix the method names with kendo (or some 2-letter abbreviation)?
I really believe that this setup is counterproductive to developers, as it gets in the way of the incredible strength of chaining methods that is so powerful in jQuery. It also goes against the guidelines as presented on the jQuery site: http://docs.jquery.com/Plugins/Authoring
So please have this for review for your next release - your widgets look great, but we would like to have this reviewed nevertheless :)

$('div.grid').kendoGrid(); // initialise grid
$('div.grid').kendoGrid('refresh'); // call refresh method
in stead of
$('div.grid').kendoGrid(); // initialise grid
$('div.grid').data('kendoGrid').refresh(); // call refresh method
because in this last example, I will no longer hold the $('div.grid') object...
Indeed jQuery UI extends jQuery.fn with only one method per widget just as Kendo UI does. It would have been wrong to add all widget methods to all jQuery instances. Imagine what would happen when there are duplicate method names.
jQuery UI invented a solution as you have pointed out:
$('div.grid').kendoGrid('refresh');
It is entirely possible for us to implement the same workaround. I suggest you create a new user voice item so people can vote for it.
Atanas Korchev
the Telerik team

I'll raise a user voice item for you ;)


Sorry for bumping this again, but has this really been completed?!?
I never got any response on my uservoice feedback...
Here is what the response to your user voice item was:
Brandon Satrom (Program Manager, Kendo UI, Kendo UI) responded May 15, 2012
Delivered in the Q1 service pack.
So yes, this was completed last May and shipped with Q1 2012 SP1. Here is a demo: http://jsbin.com/uyusuk/1/edit
Atanas Korchev
the Telerik team