13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Combo Boxes</title>
 
    <!-- ExtJS -->
    <script type="text/javascript" src="../../examples/shared/include-ext.js"></script>
    <script type="text/javascript" src="../../examples/shared/options-toolbar.js"></script>
 
    <!-- Shared -->
    <link rel="stylesheet" type="text/css" href="../shared/example.css" />
 
    <!-- GC -->
 
    <!-- Example -->
    <script type="text/javascript" src="combos.js"></script>
    <style type="text/css">
        .example {
            width: 600px;
            border: 1px solid #CCC;
            padding: 0 10px;
            margin: 0 0 10px;
        }
        .x-fieldset {
            margin-top: 20px;
        }
        #transformCombo label {
            display: block;
            margin: 1em 0 2px;
        }
    </style>
 
</head>
<body>
 
<h1>Combo Boxes</h1>
    <p>ComboBoxes can use any type of Ext.data.Store as a data source.</p>
    <p>This means your data can be XML, JSON, arrays or any other supported format. It can be loaded using
    Ajax, JSONP or locally.</p>
<p>The js is not minified so it is readable. See <a href="combos.js">combos.js</a>.</p>
 
<div class="example">
    <h2>Remote query mode</h2>
    <p>This ComboBox uses <code>queryMode: 'remote'</code> to perform the query on a remote API which
    returns book titles which match the typed string.</p>
 
    <div id="remoteQueryCombo"></div>
 
    <pre class="code x-hide-display" id="remoteQueryComboCode">
    var bookStore = new Ext.data.Store({
        proxy: {
            type: 'jsonp',
            startParam: 'startIndex',
            limitParam: 'maxResults',
            url: 'https://www.googleapis.com/books/v1/volumes',
            reader: {
                type: 'json',
                totalProperty: 'totalItems',
                root: 'items'
            }
        },
        fields: [{
            name: 'title',
            mapping: function(raw) {
                var result = raw.volumeInfo.title;
                if (raw.volumeInfo.subtitle) {
                    result = result + ' - ' + raw.volumeInfo.subtitle;
                }
                return result;
            }
        }, {
            name: 'ISBN',
            mapping: function(raw) {
                var ids = raw.volumeInfo.industryIdentifiers;
                return ids ? ids[0].identifier : 'No identifier for this book';
            }
        }]
    });
 
    var bookCombo = Ext.create('Ext.form.field.ComboBox', {
        fieldLabel: 'Select Book',
        renderTo: 'remoteQueryCombo',
        displayField: 'title',
        valueField: 'ISBN',
        width: 500,
        labelWidth: 130,
        store: bookStore,
        queryParam: 'q',
        queryMode: 'remote',
 
        // Do not use the default "all" for unbounded remote datasets.
        // We could also have used the hideTrigger config
        triggerAction: 'query',
 
         listConfig: {
            getInnerTpl: function() {
                return '{%var value = this.field.getRawValue().replace(/([.?*+^$[\\]\\\\(){}|-])/g, "\\\\$1");%}' + 
                    '{[values.title.replace(new RegExp(value, "i"), function(m) {return "&lt;b>" + m + "&lt;/b>";})]}';
            }
        },
        listeners: {
            select: function() {
                Ext.Msg.alert('Chosen book', 'Buying ISBN: ' + this.getValue());
            }
        }
    });
    </pre>
</div>
 
<div class="example">
    <h2>Remote loaded, local query mode</h2>
    <p>This ComboBox uses remotely loaded data, to perform querying client side.</p>
    <p>This is suitable when the dataset is not too big or dynamic to be manipulated locally</p>
    <p>This example uses a custom template for the dropdown list to illustrate grouping.</p>
 
    <div id="remoteLoadedCombo"></div>
 
    <pre class="code x-hide-display" id="remoteLoadedComboCode">
    var Country = Ext.define('Country', {
            extend: 'Ext.data.Model',
            fields: ['name', {
                name: 'region',
                mapping: 'region.value'
            }]
        }),
        countryStore = new Ext.data.Store({
            model: Country,
            proxy: {
                type: 'jsonp',
                callbackKey: 'prefix',
                limitParam: 'per_page',
                url: 'http://api.worldbank.org/countries?format=jsonp',
                reader: {
                    type: 'json',
 
                    // Response is an array where element [1] is the array of records
                    getData: function(raw) {
                        return raw[1];
                    }
                }
            },
            sorters: {
                property: 'region'
            },
            
            // Data includes aggregates which are not countries
            filters: {
                fn: function(rec) {
                    return rec.get('region') !== 'Aggregates'
                }
            },
            // Load whole dataset.
            // API only returns 25 by default.
            pageSize: 1000,
            autoLoad: true
        });
 
    var countryCombo = Ext.create('Ext.form.field.ComboBox', {
        fieldLabel: 'Select Country',
        renderTo: 'remoteLoadedCombo',
        displayField: 'name',
        width: 500,
        labelWidth: 130,
        store: countryStore,
        queryMode: 'local',
        tpl: '&lt;ul class="x-list-plain">' +
                '{% var lastRegion, region; %}' +
                '&lt;tpl for=".">' +
                    // Only show region headers when there are more than 10 choices
                    'if (this.store.getCount() > 10 && region !== lastRegion) {' + 
                    'if (region !== lastRegion) {' + 
                        'lastRegion = region;%}' +
                        '&lt;li class="x-grid-group-hd x-grid-group-title">{region}&lt;/li>' +
                    '{%}%}'+
                    '&lt;li class="x-boundlist-item">' +
                        '{name}' +
                    '&lt;/li>'+
                '&lt;/tpl>'+
            '&lt;/ul>'
    });
    </pre>
</div>
 
<div class="example">
    <h2>Locally loaded data</h2>
    <p>This ComboBox uses local data from a JS array:</p>
 
    <div id="simpleCombo"></div>
 
    <pre class="code x-hide-display" id="simpleComboCode">// Define the model for a State
Ext.regModel('State', {
    fields: [
        {type: 'string', name: 'abbr'},
        {type: 'string', name: 'name'},
        {type: 'string', name: 'slogan'}
    ]
});
 
// The data store holding the states
var store = Ext.create('Ext.data.Store', {
    model: 'State',
    data: states
});
 
// 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
});</pre>
</div>
 
<div class="example">
    <h2>Custom Item Templates</h2>
    <p>This ComboBox 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.</p>
 
    <div id="customTplCombo"></div>
 
    <pre class="code x-hide-display" id="customTplComboCode">// Define the model for a State
Ext.regModel('State', {
    fields: [
        {type: 'string', name: 'abbr'},
        {type: 'string', name: 'name'},
        {type: 'string', name: 'slogan'}
    ]
});
 
// The data store holding the states
var store = Ext.create('Ext.data.Store', {
    model: 'State',
    data: states
});
 
// 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 '&lt;div data-qtip="{name}. {slogan}">{name} ({abbr})&lt;/div>';
        }
    }
});</pre>
</div>
 
<div class="example">
    <h2>Multiple Selection</h2>
    <p>This ComboBox uses the same data once again, but allows selecting multiple values.</p>
 
    <div id="multiSelectCombo"></div>
 
    <pre class="code x-hide-display" id="multiSelectComboCode">// Define the model for a State
Ext.regModel('State', {
    fields: [
        {type: 'string', name: 'abbr'},
        {type: 'string', name: 'name'},
        {type: 'string', name: 'slogan'}
    ]
});
 
// The data store holding the states
var store = Ext.create('Ext.data.Store', {
    model: 'State',
    data: states
});
 
// 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'
});</pre>
</div>
 
<div class="example">
    <h2>Transformation</h2>
    <p>ComboBoxes can also be created from existing HTML <code>&lt;select&gt;</code> elements on the page by
    specifying the <code>transform</code> config. This allows creation of rich ComboBox fields with autocompletion
    and list filtering, in an unobtrusive way.</p>
 
    <div id="transformCombo">
        <label for="stateSelect">Transformed select:</label>
        <select name="state" id="stateSelect">
        <option value="AL">Alabama</option>
        <option value="AK">Alaska</option>
        <option value="AZ">Arizona</option>
        <option value="AR">Arkansas</option>
        <option value="CA">California</option>
        <option value="CO">Colorado</option>
        <option value="CT">Connecticut</option>
        <option value="DE">Delaware</option>
        <option value="FL">Florida</option>
        <option value="GA">Georgia</option>
        <option value="HI">Hawaii</option>
        <option value="ID">Idaho</option>
        <option value="IL">Illinois</option>
        <option value="IN">Indiana</option>
        <option value="IA">Iowa</option>
        <option value="KS">Kansas</option>
        <option value="KY">Kentucky</option>
        <option value="LA">Louisiana</option>
        <option value="ME">Maine</option>
        <option value="MD">Maryland</option>
        <option value="MA">Massachusetts</option>
        <option value="MI">Michigan</option>
        <option value="MN">Minnesota</option>
        <option value="MS">Mississippi</option>
        <option value="MO">Missouri</option>
        <option value="MT">Montana</option>
        <option value="NE">Nebraska</option>
        <option value="NV">Nevada</option>
        <option value="NH">New Hampshire</option>
        <option value="NJ">New Jersey</option>
        <option value="NM">New Mexico</option>
        <option value="NY">New York</option>
        <option value="NC">North Carolina</option>
        <option value="ND">North Dakota</option>
        <option value="OH" selected>Ohio</option>
        <option value="OK">Oklahoma</option>
        <option value="OR">Oregon</option>
        <option value="PA">Pennsylvania</option>
        <option value="RI">Rhode Island</option>
        <option value="SC">South Carolina</option>
        <option value="SD">South Dakota</option>
        <option value="TN">Tennessee</option>
        <option value="TX">Texas</option>
        <option value="UT">Utah</option>
        <option value="VT">Vermont</option>
        <option value="VA">Virginia</option>
        <option value="WA">Washington</option>
        <option value="WV">West Virginia</option>
        <option value="WI">Wisconsin</option>
        <option value="WY">Wyoming</option>
        </select>
 
        <label for="stateSelectOrig">Originally looked like:</label>
        <select name="state-orig" id="stateSelectOrig">
        <option value="AL">Alabama</option>
        <option value="AK">Alaska</option>
        <option value="AZ">Arizona</option>
        <option value="AR">Arkansas</option>
        <option value="CA">California</option>
        <option value="CO">Colorado</option>
        <option value="CT">Connecticut</option>
        <option value="DE">Delaware</option>
        <option value="FL">Florida</option>
        <option value="GA">Georgia</option>
        <option value="HI">Hawaii</option>
        <option value="ID">Idaho</option>
        <option value="IL">Illinois</option>
        <option value="IN">Indiana</option>
        <option value="IA">Iowa</option>
        <option value="KS">Kansas</option>
        <option value="KY">Kentucky</option>
        <option value="LA">Louisiana</option>
        <option value="ME">Maine</option>
        <option value="MD">Maryland</option>
        <option value="MA">Massachusetts</option>
        <option value="MI">Michigan</option>
        <option value="MN">Minnesota</option>
        <option value="MS">Mississippi</option>
        <option value="MO">Missouri</option>
        <option value="MT">Montana</option>
        <option value="NE">Nebraska</option>
        <option value="NV">Nevada</option>
        <option value="NH">New Hampshire</option>
        <option value="NJ">New Jersey</option>
        <option value="NM">New Mexico</option>
        <option value="NY">New York</option>
        <option value="NC">North Carolina</option>
        <option value="ND">North Dakota</option>
        <option value="OH" selected>Ohio</option>
        <option value="OK">Oklahoma</option>
        <option value="OR">Oregon</option>
        <option value="PA">Pennsylvania</option>
        <option value="RI">Rhode Island</option>
        <option value="SC">South Carolina</option>
        <option value="SD">South Dakota</option>
        <option value="TN">Tennessee</option>
        <option value="TX">Texas</option>
        <option value="UT">Utah</option>
        <option value="VT">Vermont</option>
        <option value="VA">Virginia</option>
        <option value="WA">Washington</option>
        <option value="WV">West Virginia</option>
        <option value="WI">Wisconsin</option>
        <option value="WY">Wyoming</option>
        </select>
    </div>
 
    <pre class="code x-hide-display" id="transformComboCode">var transformed = Ext.create('Ext.form.field.ComboBox', {
    typeAhead: true,
    transform: 'stateSelect',
    width: 135,
    forceSelection: true
});</pre>
</div>
 
</body>
</html>