Clear items in DropDownList

6 posts, 0 answers
  1. Rich
    Rich avatar
    80 posts
    Member since:
    Jul 2012

    Posted 30 Oct 2012 Link to this post

    Hi All, i cannot figure this out.

    I have a dropdownlist with a datasource. I need to clear the items in the list to sort of initialize it after someone makes an selection and some other things happen..

    How can i clear the items in the list? Clear them from the datasource? thanks.
  2. Dimo
    Admin
    Dimo avatar
    8456 posts

    Posted 31 Oct 2012 Link to this post

    Hello Rich,

    You can use:

    var ddl = $("#clientid").data("kendoDropDownList");
    ddl.dataSource.data({}); // clears dataSource
    ddl.text(""); // clears visible text
    ddl.value(""); // clears invisible value

    Regards,
    Dimo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Chuck
    Chuck avatar
    2 posts
    Member since:
    Mar 2011

    Posted 09 Sep 2014 Link to this post


    I use that exact code:
    var ddl = $("#ddlSubAction").data("kendoDropDownList");
    ddl.dataSource.data({});

    But instantly recive an error that states that the object does not support the property or method 'slice'
  4. Dimo
    Admin
    Dimo avatar
    8456 posts

    Posted 10 Sep 2014 Link to this post

    Hello Chuck,

    You are probably using a newer Kendo UI version. In this case, please provide an empty array argument instead of an empty object.

    Regards,
    Dimo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  5. nhat
    nhat avatar
    1 posts
    Member since:
    Feb 2019

    Posted 23 Feb in reply to Chuck Link to this post

    ddl.dataSource.data([]);

  6. Nithya
    Nithya avatar
    2 posts
    Member since:
    Jul 2019

    Posted 27 Sep Link to this post

    var dropdownlist = $("#Merchant").data("kendoDropDownList");
                    dropdownlist.enable(false); // Disable the dropdownlist
             
                $("#Merchant").data("kendoDropDownList").value(null); // Clear the value 
Back to Top