This is a migrated thread and some comments may be shown as answers.

Why aren't widget methods just added through object extention?

8 Answers 92 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 20 Mar 2012, 04:06 PM
Okay

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

Sort by
0
Atanas Korchev
Telerik team
answered on 20 Mar 2012, 04:09 PM
Hi,

 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
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David
Top achievements
Rank 1
answered on 22 Mar 2012, 02:23 PM
Hi again,


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 :)
0
David
Top achievements
Rank 1
answered on 22 Mar 2012, 02:26 PM
just o be complete, as my first topicpost was a bit wrong, I would expect the following to be possible:

$('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...
0
Atanas Korchev
Telerik team
answered on 22 Mar 2012, 03:25 PM
Hi,

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. 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David
Top achievements
Rank 1
answered on 22 Mar 2012, 03:31 PM
yes - I didn't mean to add the functions (that was indeed a bad way of saying) - I wanted to say the .kendoGrid('method') method.  this is not "invented by jQueryUI" though, but is standard way of working if you follow the guidelines on how to implement plugins.

I'll raise a user voice item for you ;)
0
David
Top achievements
Rank 1
answered on 22 Mar 2012, 04:09 PM
0
David
Top achievements
Rank 1
answered on 06 Mar 2013, 12:22 PM
Hi again

Sorry for bumping this again, but has this really been completed?!?
I never got any response on my uservoice feedback...
0
Atanas Korchev
Telerik team
answered on 06 Mar 2013, 12:50 PM
Hello,

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

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
David
Top achievements
Rank 1
Share this question
or