X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/d41dc04ad17d1d9125fb2cf72db2b4782dbe3a8c..f562e4c6e5fac7bcb445985b99acbea4d706e6f0:/examples/form/combos.html?ds=sidebyside diff --git a/examples/form/combos.html b/examples/form/combos.html index e96a7a4b..d0bbbbaa 100644 --- a/examples/form/combos.html +++ b/examples/form/combos.html @@ -3,235 +3,271 @@ 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.SimpleStore({
-    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.SimpleStore({
-    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 SimpleStore 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', + listConfig: { + 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
+});
+
+