X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/0494b8d9b9bb03ab6c22b34dae81261e3cd7e3e6..7a654f8d43fdb43d78b63d90528bed6e86b608cc:/examples/form/combos.html diff --git a/examples/form/combos.html b/examples/form/combos.html index 21ab1799..e429671a 100644 --- a/examples/form/combos.html +++ b/examples/form/combos.html @@ -3,235 +3,269 @@ Combo Boxes - - - - - - + + + - + + - + - - - - + - +

Combo Boxes

The js is not minified so it is readable. See combos.js.

-

-Data Sources
-The combo box can use any type of Ext.data.Store as its data source. - This means your data can be XML, JSON, arrays or any other supported format. It can be loaded using +

+

Data Sources

+

The combo box can use any type of Ext.data.Store as its data source. + This means your data can be XML, JSON, arrays or any other supported format. It can be loaded using Ajax, via script tags or locally. This combo uses local data from a JS array:

-
- -
-
-
// simple array store
-var store = new Ext.data.ArrayStore({
-    fields: ['abbr', 'state'],
-    data : exampleData
+
+    
+ +
// Define the model for a State
+Ext.regModel('State', {
+    fields: [
+        {type: 'string', name: 'abbr'},
+        {type: 'string', name: 'name'},
+        {type: 'string', name: 'slogan'}
+    ]
 });
-var combo = new Ext.form.ComboBox({
-    store: store,
-    displayField:'state',
-    typeAhead: true,
-    mode: 'local',
-    triggerAction: 'all',
-    emptyText:'Select a state...',
-    selectOnFocus:true,
-    applyTo: 'local-states'
+
+// The data store holding the states
+var store = Ext.create('Ext.data.Store', {
+    model: 'State',
+    data: states
 });
-
-
- -

- The combo below uses the same data, but also illustrates how to use an optional - custom template to create custom UI renditions for list items. In this case, - each item has a popup QuickTip which displays the state's nickname when hovered over. -

-
- + +// Simple ComboBox using the data store +var simpleCombo = Ext.create('Ext.form.field.ComboBox', { + fieldLabel: 'Select a single state', + renderTo: 'simpleCombo', + displayField: 'name', + width: 500, + labelWidth: 130, + store: store, + queryMode: 'local', + typeAhead: true +});
-
-
// simple array store
-var store = new Ext.data.ArrayStore({
-    fields: ['abbr', 'state', 'nick'],
-    data : exampleData
+
+
+

Custom Item Templates

+

The combo below uses the same data, but also illustrates how to use an optional + custom template to create custom UI renditions for list items by overriding the getInnerTpl method. In this case + each item shows the state's abbreviation, and has a QuickTip which displays the state's nickname when hovered over.

+ +
+ +
// Define the model for a State
+Ext.regModel('State', {
+    fields: [
+        {type: 'string', name: 'abbr'},
+        {type: 'string', name: 'name'},
+        {type: 'string', name: 'slogan'}
+    ]
 });
-var comboWithTooltip = new Ext.form.ComboBox({
-    tpl: '<tpl for="."><div ext:qtip="{state}. {nick}" class="x-combo-list-item">{state}</div></tpl>',
-    store: store,
-    displayField:'state',
-    typeAhead: true,
-    mode: 'local',
-    triggerAction: 'all',
-    emptyText:'Select a state...',
-    selectOnFocus:true,
-    applyTo: 'local-states-with-qtip'
+
+// The data store holding the states
+var store = Ext.create('Ext.data.Store', {
+    model: 'State',
+    data: states
 });
-
-
- -

-The combo box can also use plain array data directly as its data source, wrapping the array internally -with a ArrayStore as needed. You can pass a 1-dimensional or multi-dimensional array as the store config:

-
- + +// ComboBox with a custom item template +var customTplCombo = Ext.create('Ext.form.field.ComboBox', { + fieldLabel: 'Select a single state', + renderTo: 'customTplCombo', + displayField: 'name', + width: 500, + labelWidth: 130, + store: store, + queryMode: 'local', + getInnerTpl: function() { + return '<div data-qtip="{name}. {slogan}">{name} ({abbr})</div>'; + } +});
-
-
var comboFromArray = new Ext.form.ComboBox({
-    store: exampleData, //direct array data
-    typeAhead: true,
-    triggerAction: 'all',
-    emptyText:'Select a state...',
-    selectOnFocus:true,
-    applyTo: 'array-states'
+
+
+

Multiple Selection

+

The combo below uses the same data once again, but allows selecting multiple values.

+ +
+ +
// Define the model for a State
+Ext.regModel('State', {
+    fields: [
+        {type: 'string', name: 'abbr'},
+        {type: 'string', name: 'name'},
+        {type: 'string', name: 'slogan'}
+    ]
 });
-
-
- -

-Unobtrusive
-The combo box can very easily be used to convert existing select elements into auto-completing, filtering combos. -

-
-Transformed select:
-

-

-Originally looked like:
-

-
-
var converted = new Ext.form.ComboBox({
-    typeAhead: true,
-    triggerAction: 'all',
-    transform:'state',
-    width:135,
-    forceSelection:true
+
+// The data store holding the states
+var store = Ext.create('Ext.data.Store', {
+    model: 'State',
+    data: states
 });
-
-
-

- Grid Editor
- Click here to see the combo as a grid editor. -

-
-

- Templates and Ajax
- Click here for a more advanced example. -

-



+ +// ComboBox with multiple selection enabled +var multiCombo = Ext.create('Ext.form.field.ComboBox', { + fieldLabel: 'Select multiple states', + renderTo: 'multiSelectCombo', + multiSelect: true, + displayField: 'name', + width: 500, + labelWidth: 130, + store: store, + queryMode: 'local' +});
+
+ +
+

Transformation

+

ComboBoxes can also be created from existing HTML <select> elements on the page by + specifying the transform config. This allows creation of rich ComboBox fields with autocompletion + and list filtering, in an unobtrusive way.

+ +
+ + + + + +
+ +
var transformed = Ext.create('Ext.form.field.ComboBox', {
+    typeAhead: true,
+    transform: 'stateSelect',
+    width: 135,
+    forceSelection: true
+});
+
+