Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Niranjan Avadhuta on Mar 17, 2009 08:56
open dhtmlx forum
dhtmlx combobox

I am using DHTMLX combo box. One of the lists has about 100 items. By default the page shows all the items when the dropdown image is clicked. If there are 100 items in combo box, we sell the list of 100 items. How to set the size of the list, so that only first 5 items are shown when selected. I used enableOptionAutoHeight(false) property, but it doesn't limit the display of the list. Here is what I did.

Tested enableOptionAutoHeight method with both true and false options. No change.
Used enableOptionAutoHeight method before loading the combo box and after loading the combo. No change.
Checked the css file of dhtmlcombo. The .dhx_combo_list class has height set to 100px;
When I debug javascript I see z.DOMlist.style.height as 100 px.

How to test?

Please check this website I found on internet. http://3d-plastic.eu/js/dhtmlxCombo/samples/options/combo_auto_size.html
When initally displayed, the enable and disable of Auto height work fine. No change height to 100, click on height, and click on enable. You see all the items in the list. When clicked on disable, you see all the items. Enable /disable doesn't have any difference.

Following is my script. ename is the selectbox name,k dispvals is string array of list of values, dispval is the default value.

function BuildComboBox(ename, dispvals, dispval) {

var einCombo;
try { einCombo = dhtmlXComboFromSelect(ename); } catch (err) { return }
if (einCombo == null) return;
einCombo.enableOptionAutoWidth(false);

einCombo.clearAll(true);
var xmlstr ='<list>';
for (i = 0; i < dispvals.length; i++) {
if (dispvals[i] != '') {
// einCombo.addOption(dispvals[i], dispvals[i]);
xmlstr += '<option>' + dispvals[i] + '</option>';
}
}
xmlstr += '</list>';
einCombo.loadXMLString(xmlstr);

einCombo.setComboText(dispval);

einCombo.disable('false');
einCombo.attachEvent("onChange", function(event) {
var seltext = this.getActualValue();
FieldValueChanged(this.enumname, seltext); //custom javascript function

});
einCombo.attachEvent("onClick", function() {
var seltext = this.getActualValue();
if ((seltext == 'Enter Specified Amount') || (seltext == 'Specify Amount'))
this.setComboText('');
});
return einCombo;

}

Please help me. Thanks,
Niranjan Avadhuta.
Answer posted by Alex (support) on Mar 18, 2009 02:40

Hello, 

The issue is caused by setting new height = 200px before calling enableOptionAutoHeight(1);. So, when you disable auto height, the height is changed to 200px. 

You can use the following approach to set 100px height:

combo.enableOptionAutoHeight(0);

combo.setOptionHeight(100);

Or you can set default height manually: combo._listHeightConf = 100;

Answer posted by Niranjan Avadhuta on Mar 19, 2009 09:43
I tried setting both setOptionHeight along with enableOptionAutoHeight(0) and _listHeigthConf. The entire list shows up in any case. I want to limit the list with five items with vertical scroll bar. Please take a look at javascript function BuildComboBox I sent earlier. I added method setOptionHeight to it before attachEvent. It doesn't control the list. Is there anything missing?
Answer posted by Alex (support) on Mar 19, 2009 11:00

Please, have a look at the attached sample. 

Locally it works correctly.

The code snippet, which you have provided, doesn't contain enableOptionAutoHeight and setOptionHeight calls.

Attachments (1)