Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove item of kendo dropDownList if it is the last one?

I can remove all items except the last one from the kendo dropdownlist. After the last one is removed, the previous items reappear.

Here is a jsFiddle: http://jsfiddle.net/lpoellabauer/Jw4Cz/

var dropDown = $("select").data("kendoDropDownList");
var itemToRemove = dropDown.dataSource.at(0);
dropDown.dataSource.remove(itemToRemove);
dropDown.select(0);

Any ideas how to solve this?

like image 415
l.poellabauer Avatar asked Oct 07 '22 23:10

l.poellabauer


1 Answers

HTML:

<select>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option id="none" value="none"></option>
</select>

<a href="#">remove first</a>

JS:

$("select").kendoDropDownList();

$("a").click(function(){
    var dropDown = $("select").data("kendoDropDownList");
    var itemToRemove = dropDown.dataSource.at(0);
    dropDown.dataSource.remove(itemToRemove);
    dropDown.select(0);
});
$('none').css({display:none});

like image 114
user1301411 Avatar answered Oct 12 '22 19:10

user1301411