Combo
Combo (dropdown) widget. Consists of a text field with a trigger icon, which displays a List. Can be populated from a Store.
Please be aware that when populating the Combo with objects or records, you have to configure valueField and displayField to point to the correct field names in your data.
This field can be used as an editor for the Column.
Basic scenarios
Loading data from simple string array:
Filtering on typing will still work when non-editable. The characters typed are collected and used to filter the list of items in the picker. The typed value expires after 2 seconds of inactivity. This is useful when a non-editable Combo has a very large dataset and you want to filter it by typing.
The combo's configured primaryFilter is used which uses the startsWith operator by default.
Basic scenarios
Strict picker width matching
By default, a Combo's picker, auto widths around its visible content, but will be at least the width of the Combo's input area. See the first example above.
To enforce strict width matching of the picker to the input area, configure the combo's picker like this
const combo = new Combo({
items : ['Small', 'Mediunm', 'Large', 'Ridiculously huge which would cause a very wide dropdown'],
placeholder : 'Pick size of diamond for ring',
picker : {
align : {
// Override default which is 'min'
matchSize : true
}
}
});
Autocomplete / Type ahead
Implementing remote type-ahead functionality is simple, configure a store with readUrl and define the minChars required to type before remote loading is triggered.
Snippet: Loading data from simple string array
const combo = new Combo({
items : ['Small', 'Smaller', 'Really small', 'Tiny'],
placeholder : 'Pick size of diamond for ring'
});
Loading data from array with item configs:
const combo = new Combo({
items : [{ value: 'a', text: 'First' }, { value: 'z', text: 'Last' }]
});
Loading data from store:
const combo = new Combo({
store : memberStore,
valueField : 'id',
displayField : 'name'
});
Editability
When configured with editable : false, the field may still be operated and have a value selected from the picker.
This setting just means that the textual input field may not be edited by the UI. In this mode, the picker's displayed dataset my still be filtered by typing while the picker is visible.
The combo's configured primaryFilter is used which uses the startsWith operator by default.
Grouping the list
To group the list contents, simply group your store using groupers. You can decide if clicking a header should toggle all group children (or if it should do nothing) with the allowGroupSelect flag.
const combo = new Combo({
width : 400,
displayField : 'name',
valueField : 'id',
multiSelect : true,
picker : {
allowGroupSelect : false,
// Show icon based on group name
groupHeaderTpl : (record, groupName) => `
<i class="icon-${groupName}"></i>${groupName}
`
},
value : [1, 4],
store : new Store({
fields : [
'type'
],
groupers : [
{ field : 'type', ascending : true }
],
data : [
{ id : 1, name : 'pizza', type : 'food' },
{ id : 2, name : 'bacon', type : 'food' },
{ id : 3, name : 'egg', type : 'food' },
{ id : 4, name : 'Gin tonic', type : 'drinks' },
{ id : 5, name : 'Wine', type : 'drinks' },
{ id : 6, name : 'Beer', type : 'drinks' }
]
})
});
This demo uses multi-selection and a grouped list:
Shared Stores
More than one Combo may share a Store if they are required to draw their values from a shared data set.
The only limitation here is that the characteristics of the filter that is applied to the store by typing are inherited from the first combo. So for example, all would be caseSensitive or all case-insensitve, and all would use the same filterOperator.
In the example below, all three email address inputs use the same store of recipients.
This may be operated using the keyboard. ArrowDown opens the picker, and then ArrowDown and ArrowUp navigate the picker's options. Enter selects an active option in the picker. Escape closes the picker.
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
Configure this as
falseto disable keyboard filtering completely -
Provide a function that returns items to be shown in the combo's selector.
-
Configure as
trueto force case matching when filtering the dropdown list based upon the typed value. -
trueto clear value typed to a multiselect combo when picker is collapsed -
Specify
falseto not clear value typed to a multiselect combo when an item is selected. -
Set to
trueto clear this field when user empties the input element -
Field used for item text when populating from store
-
If
false, filtering will be triggered once you exceed minChars. To filter only when hitting Enter key, set this totrue; -
If the dropdown is to be populated with a filtered query to a remote server, specify the name of the parameter to pass the typed string here. By default, the string is simply sent as the value of the parameter. For special encoding, configure the combo with encodeFilterParams
-
When multiSelect is
true, you may configurefilterSelectedastrueto hide items in the dropdown when they are added to the selection. It will appear as if the requested item has "moved" into the field's ChipView. -
By default, the picker is hidden on selection in single select mode, and remains to allow more selections when multiSelect is
true. Setting this to aBooleanvalue can override that default. -
Configure as
trueto hide the expand trigger. This is automatically set totrueif remote filtering is enabled by setting the filterParamName config. -
CSS class to add to picker
-
Configure this as
trueand the items display field values will be localized. The display field values need to be a locale string. -
A key value which, when typed in a multiSelect Combo, selects the currently active item in the picker, and clears the input field ready for another match to be typed.
-
When the Combo is
editable : false, keystrokes are listened for and a filter string built which filters down the visible result. After a timeout of nonEditableFilterTimeout milliseconds, the filter string is cleared.Has a corresponding runtime nonEditableFilterTimeout property.
-
This implies that the picker will display an anchor pointer, but also means that the picker will align closer to the input field so that the pointer pierces the pickerAlignElement
-
Width of picker, defaults to this combo's pickerAlignElement width
-
Configure this as
trueto reapply sorting after localizing the items. -
Store used to populate items. Also accepts a Store config object
Has a corresponding runtime store property.
-
How to query the store upon click of the expand trigger. Specify one of these values:
'all'- Clear the filter and display the whole dataset in the dropdown.'last'- Filter the dataset using the last filter value.null/any other - Use the value in the input field to filter the dataset.
-
trueto cause the field to be in an invalid state while the typed filter string does not match a record in the store. -
The initial value of this Combo box. In single select mode (default) it's a simple string value, for multiSelect mode, it should be an array of record ids.
Has a corresponding runtime value property.
Properties
Properties are getters/setters or publicly accessible variables on this class-
A constant value for the triggerAction config to indicate that clicking the trigger should filter the dataset using the last filter query string, not the input field value.
-
Identifies an object as an instance of Combo class, or subclass thereof.
-
Returns array of the Combo's inner HTML elements. This getter can be overridden.
-
Returns
trueif this field has no selected records. -
When the Combo is
editable : false, keystrokes are listened for and a filter string built which filters down the visible result. After a timeout of nonEditableFilterTimeout milliseconds, the filter string is cleared.Has a corresponding nonEditableFilterTimeout config.
-
Get selected record.
-
Get the selected record(s).
-
Store used to populate items. Also accepts a Store config object
Has a corresponding store config.
-
Identifies an object as an instance of Combo class, or subclass thereof.
Functions
Functions are methods available for calling on the class-
changeItems( )private
Prepares items to work in attached menu (converts strings to items)
-
changePicker( )internal
Creates default picker widget
-
internalOnInput( )private
User types into input field in editable combo, show list and filter it.
-
onEditComplete( )internal
Check if field value is valid
-
onTriggerClick( )private
User clicked trigger icon, toggle list.