I think you could determine the length in the data source itself, and then resize the drop down list. This works for a demo project, but I think, depending on the styles and indents you might need, to improve the calibration technique a bit more.
Determines the size of the elements (again, if you use objects instead of strings inside the array, you may need to modify it a bit (you can pass displayMember if you want)
function determineWidth(ds) { var l = ds.length, selement = document.createElement('span'), maxwidth = 0, curwidth = 0; selement.style = 'position: fixed; left: -500px; top: -500px;'; document.body.appendChild(selement); for (var i = 0; i < l; i++) { $(selement).html(ds[i]); curwidth = $(selement).width(); if (curwidth < maxwidth) { continue; } maxwidth = curwidth; } document.body.removeChild(selement); return curwidth + 24; }
inside the combobox, you can bind to the dataBound event, determine the size of the elements, and update the container and parent element to match the actual size
$("#combobox").kendoComboBox({ index: 0, dataSource: { data: ["One", "Two", "Hundred"] }, dataBound: function() { var width = determineWidth(this.dataSource.data()); $('#combobox-container').find('span>.k-dropdown-wrap').width(width).parent().width(width); } }); var comboBox = $("#combobox").data("kendoComboBox");
the fiddle can be found here: http://jsfiddle.net/Icepickle/gLbLtjhf/
source share