1 Answer, 1 is accepted
1
Nohinn
Top achievements
Rank 1
answered on 06 Sep 2012, 02:06 PM
In the select callback of the dropdownlist:
You have a sample here too:
http://demos.kendoui.com/web/dropdownlist/events.html
$(
'#input'
).kendoDropDownList({
select:
function
(e) {
var
index = e.item.index();
}
});
You have a sample here too:
http://demos.kendoui.com/web/dropdownlist/events.html
David
commented on 06 Sep 2012, 03:43 PM
Top achievements
Rank 1
That works in the select function and helps me in one of the 2 cases. I still don't see how I can arbitrarily get the selected index for the DropDownList (outside of the select function).
Nohinn
commented on 06 Sep 2012, 03:47 PM
Top achievements
Rank 1
var index = $('#input').data('kendoDropDownList').select();
That would be with the dropdown closed without using the select callback, and is zero-based.
Michael
commented on 25 Aug 2021, 03:25 PM
Top achievements
Rank 1
This worked wonderfully, but one thing to remember is if there is an option label, it means the index of the item ($('#input').data('kendoDropDownList').select();) is not the same as the index in the dataSource. Discovered this when trying t remove a selected item from a datasource after adding it to another list.
Neli
commented on 30 Aug 2021, 10:31 AM
Telerik team
Hi Michael,
indeed, when the optionLabel is used in the configuration, its value is placed in the DropDownList popup as well under index 0.
Regards.
Lee
commented on 01 Apr 2022, 05:28 PM
Top achievements
Rank 2
Bronze
Bronze
Bronze
How would this work outside of an event listener. For example, how would I create a function called "getIndex" and run that from the console?
Michael
commented on 01 Apr 2022, 06:22 PM
Top achievements
Rank 1
@Lee - did you see the comment from @Nohinn from 2012 above?
Lee
commented on 01 Apr 2022, 06:27 PM
Top achievements
Rank 2
Bronze
Bronze
Bronze
Thanks. @Nohinn's comment works.