Setting optionLabel after initiation

6 posts, 0 answers
  1. Web
    Web avatar
    1 posts
    Member since:
    Feb 2012

    Posted 01 Jun 2012 Link to this post

    Is there a way to set the optionLabel after the initiation, because I want it to be dependent on the value of the data.
    If there is no data I want my users to know, that there are no options anymore.

    Otherwise I just do a jquery.html() on that element. But it would be nice if I can set it with the API
  2. Georgi Krustev
    Georgi Krustev avatar
    3747 posts

    Posted 05 Jun 2012 Link to this post


    Generally speaking, you can add the optionLabel after init. You just need to recreate items of the drop-down list. Other option is to use the text method of the DropDownList to set the text of the span element. Check this jsFiddle demo, which shows the both approaches.

    As a side note, I will suggest you open support tickets for your incedents. Thus our support team can handle the problems faster. We also do not guarantee answers in the forum threads.

    Kind regards,
    Georgi Krustev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Dan
    Dan avatar
    163 posts
    Member since:
    Nov 2017

    Posted 11 May 2018 in reply to Georgi Krustev Link to this post

    Hi Georgi,

    I have a requirement to have an optional label on a dropdownlist that has the datasource changed dynamic. I have updated your demo with the latest version of kendo and it does not work.

    What do I need to do to make it work?

  4. Ivan Danchev
    Ivan Danchev avatar
    1999 posts

    Posted 16 May 2018 Link to this post

    Hi Dan,

    Instead of setting the optionLabel like this:
    ddl.options.optionLabel = "Select item";

    you can use the setOptions API method to set it:
    ddl.setOptions({ optionLabel: "Select item" });

    Updated example.

    Ivan Danchev
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Dan
    Dan avatar
    163 posts
    Member since:
    Nov 2017

    Posted 22 May 2018 in reply to Ivan Danchev Link to this post

    Hi Ivan,

    Thank you, it works with your solution.

  6. Sivaramakrishna Reddy
    Sivaramakrishna Reddy avatar
    7 posts
    Member since:
    Mar 2020

    Posted 12 May in reply to Ivan Danchev Link to this post

    Thank you. It is working for me.
Back to Top