2 * @class Ext.ux.grid.menu.ListMenu
3 * @extends Ext.menu.Menu
4 * This is a supporting class for {@link Ext.ux.grid.filter.ListFilter}.
5 * Although not listed as configuration options for this class, this class
6 * also accepts all configuration options from {@link Ext.ux.grid.filter.ListFilter}.
8 Ext.define('Ext.ux.grid.menu.ListMenu', {
9 extend: 'Ext.menu.Menu',
12 * @cfg {String} labelField
17 * @cfg {String} paramPrefix
18 * Defaults to 'Loading...'.
20 loadingText : 'Loading...',
22 * @cfg {Boolean} loadOnShow
27 * @cfg {Boolean} single
28 * Specify true to group all items in this list into a single-select
29 * radio button group. Defaults to false.
33 constructor : function (cfg) {
38 * Fires when there is a change in checked items from this list
39 * @param {Object} item Ext.menu.CheckItem
40 * @param {Object} checked The checked value that was set
45 this.callParent([cfg = cfg || {}]);
47 if(!cfg.store && cfg.options){
49 for(var i=0, len=cfg.options.length; i<len; i++){
50 var value = cfg.options[i];
51 switch(Ext.type(value)){
52 case 'array': options.push(value); break;
53 case 'object': options.push([value.id, value[this.labelField]]); break;
54 case 'string': options.push([value, value]); break;
58 this.store = Ext.create('Ext.data.ArrayStore', {
59 fields: ['id', this.labelField],
68 this.add({text: this.loadingText, iconCls: 'loading-indicator'});
69 this.store.on('load', this.onLoad, this);
73 destroy : function () {
81 * Lists will initially show a 'loading' item while the data is retrieved from the store.
82 * In some cases the loaded data will result in a list that goes off the screen to the
83 * right (as placement calculations were done with the loading item). This adapter will
84 * allow show to be called with no arguments to show with the previous arguments and
85 * thus recalculate the width and potentially hang the menu from the left.
90 if(arguments.length === 0){
91 this.callParent(lastArgs);
94 if (this.loadOnShow && !this.loaded) {
97 this.callParent(arguments);
103 onLoad : function (store, records) {
105 visible = me.isVisible(),
106 gid, item, itemValue, i, len;
112 gid = me.single ? Ext.id() : null;
113 for (i = 0, len = records.length; i < len; i++) {
114 itemValue = records[i].get('id');
115 item = Ext.create('Ext.menu.CheckItem', {
116 text: records[i].get(me.labelField),
118 checked: Ext.Array.contains(me.selected, itemValue),
123 item.on('checkchange', me.checkChange, me);
133 me.fireEvent('load', me, records);
137 * Get the selected items.
138 * @return {Array} selected
140 getSelected : function () {
141 return this.selected;
145 setSelected : function (value) {
146 value = this.selected = [].concat(value);
149 this.items.each(function(item){
150 item.setChecked(false, true);
151 for (var i = 0, len = value.length; i < len; i++) {
152 if (item.value == value[i]) {
153 item.setChecked(true, true);
161 * Handler for the 'checkchange' event from an check item in this menu
162 * @param {Object} item Ext.menu.CheckItem
163 * @param {Object} checked The checked value that was set
165 checkChange : function (item, checked) {
167 this.items.each(function(item){
169 value.push(item.value);
172 this.selected = value;
174 this.fireEvent('checkchange', item, checked);