rean24
rean24

Reputation: 63

Kendo ui dropdownlist remove specific item

I have a dropdownlist that I fill from a datasource. After a specific event, I want to remove one item from my dropdownlist with id = 22. (I know it's weird and hardcoding but not much time for a newbie left). Is that possible? How can I do that?

Upvotes: 1

Views: 7950

Answers (2)

nicael
nicael

Reputation: 18997

You can access the parent of this item and then remove it as a child of parent:

  document.getElementById("22").parentNode.removeChild(document.getElementById("22"));

getElementById("22") gets an element which has id "22"

parentNode is parent of an element. In your case, it is dropdown

removeChild(document.getElementById("22")) removes the specified child from its patent. In your case, an element which has id "22".

Upvotes: 0

Drew Hayes
Drew Hayes

Reputation: 435

This is a quick and dirty way to accomplish the task using the Kendo DataSource remove method. It assumes your drop down is bound to an object containing a property called "id". If you're using the standard text/value key value pair object, then replace the if statement with if (item.Value == 22).

var dropdown = $('#dropDownId').data("kendoDropDownList");

var raw = dropdown.dataSource.data();
var length = raw.length;

var item, i;
for(i=length-1; i>=0; i--){

  item = raw[i];
  if (item.id == 22) {
    dataSource.remove(item);
    break;
  }

}

Source: http://blogs.telerik.com/kendoui/posts/13-01-29/adding_and_removing_items_in_kendo_data_datasource

Upvotes: 4

Related Questions