使用PopUp窗口构建TriggerField

时间:2010-04-12 13:07:35

标签: extjs

我构建了一个triggerField,当我按下它时,我想要一个弹出窗口,它被附加到触发器区域中的按钮(所以当我点击其他任何地方时它会消失,它会弹出到按钮时我点击按钮就像一个datepicker-popup)

我设法用Ext.window做了类似的事情,但偏移和位置不匹配。

这一切都应包含在行编辑器中。 我的代码:

new Ext.grid.GridPanel({
        store: Store,
        region:'center',
        height:150,
        //minWidth:700,
        autoScroll:true,
        listeners:{},
        plugins:[new Ext.ux.grid.RowEditor()],
      tbar: [{
            iconCls: 'icon-user-add',
            text: ' hinzufügen',
            handler: function(){
                alert("abc");
            }
        },{
            ref: '../removeBtn',
            iconCls: 'icon-user-delete',
            text: 'löschen',
            disabled: true,
            handler: function(){
                editor.stopEditing();
                var s = grid.getSelectionModel().getSelections();
                for(var i = 0, r; r = s[i]; i++){
                    store.remove(r);
                }
            }
        }],
        columns: [{
            header: 'Monate',
            dataIndex: 'MONAT',
            width: 50,
            sortable: true,
            editor: 
                new Ext.form.TriggerField({"id":"EditorMonate",items:[],
                    "onTriggerClick":function(thiss){
                    if(!Ext.getCmp("autoWMonate")){
                    var monate=new Ext.Window({"x":Ext.getCmp("EditorMonate").x,closeAction:"hide",width:275,id:"autoWMonate",layout:"table",layoutConfig: {columns: 10}});
                    var text;
                    for(var mon=1;mon<13;mon++){
                    text=mon;
                    mon?mon:text="0";
                    if(mon<10)
                        text="0"+mon;
                            monate.items.add(
new Ext.Button({cls:"x-btn",value:parseInt(text),selected:true,"text":text,id:text
                        }}}));}
                    }              Ext.getCmp("autoWMonate").hidden?Ext.getCmp("autoWMonate").show():Ext.getCmp("autoWMonate").hide();
                }})
        }
        }]
    })

2 个答案:

答案 0 :(得分:1)

问题解决了:

{
  header: 'WochenTage',
  dataIndex: 'WOCHE',
  width: 100,
  sortable: true,
  editor: new Ext.form.TriggerField({
    onTriggerClick: function(e) {
      if (!this.menu) {
        this.menu = new Ext.menu.Menu({
          items:[{xtype:"label",text:"1"},{xtype:"label",text:"2"}]
          // the items should have event listeners that set the field value accordingly 
        });
      }
      // here you would want to sync the items in the menu with the field value (this.getValue())
      // before you show the menu -- keep in mind that the menu and its children might not be rendered yet
      this.menu.showAt(e.getXY()); // or this.menu.show(this.getEl(), 'tl-bl?');
    }
  })
}

答案 1 :(得分:0)

我通过查看日期选择器的代码并在那里概括了这个想法做了类似的事情 - 使用菜单组件进行弹出行为,并将任何你喜欢的东西作为菜单中包含的单个组件。