JavaBlog.fr / Java.lu DEVELOPMENT,Sencha,WEB Sencha/ExtJs: ComboBox item separator

Sencha/ExtJs: ComboBox item separator

Hello,

A mini-post concerning the adding of a item separator in a combobox with Sencha framework.

Here’s the code for the combobox:

01...
02items: [
03{
04    xtype: 'combobox',
05    emptyText:'...',
06    allowBlank: false,
07    autoSelect: true,
08    store: storeCategoryWithAllItem,
09    mode: 'local',
10    typeAhead: true,
11    triggerAction: 'all',
12    displayField: 'value',
13    valueField: 'key',
14    fieldLabel: 'Category',
15    forceSelection: true,
16    anchor:'90%',
17    selectOnFocus:true,
18    editable: false,
19    hiddenName: 'category', // post this name
20    name: 'category',
21    value: 'All', // default value
22    tpl: '<tpl for="."><div class="x-boundlist-item">{value}</div><tpl if="xindex == 1"><hr /></tpl></tpl>'
23},
24...

And the code of the store is:

01<!-- ############## Store with 'All' item ############## -->
02Ext.namespace('Ext.huo.categoryRangeWithAllItem');
03Ext.huo.categoryRangeWithAllItem = [
04    ['All', 'All'],
05    ['QE', 'Question'],
06    ['RE', 'Answer']
07];
08  
09// simple array store
10var storeCategoryWithAllItem = new Ext.data.SimpleStore({
11    fields: ['key', 'value'],
12    data : Ext.huo.categoryRangeWithAllItem
13});

And normally you should obtain the following result:

Note: Depending the Sencha version used, if your browser or debugger reports the following error every time you click on the triangle:

1Message: 'Ext.fly(...)' is null or not an object
2Line: 58945
3Char: 9
4Code: 0
5URI: http://localhost:8080/myapplisencha/extjs/ext-all.js

this is because the style class used in the tpl is is wrong. So change the tpl to:

1tpl: '<tpl for="."><div class="x-combo-list-item">{value}</div><tpl if="xindex == 1"><hr /></tpl></tpl>'

Best regards,

Huseyin OZVEREN

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

Related Post