2013-09-03 2 views
3

탭 제목에 콤보 박스 (콤보가 더 좋을 경우 더 좋음)를 표시 할 수 있습니까?탭의 제목에 콤보 박스를 배치하는 방법은 무엇입니까?

나는 an example on jsfiddle 만든하지만 이러한 문제가 있습니다 :
1. (나는이 고정 될 수있다 생각 콤보의 옵션 목록 (마우스 클릭이 작동하지 않습니다)
2. 탭의 높이가 잘못을 표시 할 수 없습니다가 콤보에 높이를 적용하여).

샘플 코드 : 귀하의 질문에 대한

new Ext.TabPanel({ 
    renderTo: 'tab-with-combo', 
    activeTab: 0, 
    items:[ 
     { 
      title: 'First tab ' + 
       '<select>' + 
        '<option>Option 1</option>' + 
        '<option>Option 2</option>' + 
       '</select>'}, 
     {title: 'Second tab'} 
    ] 
}); 

답변

0

감사합니다,이 (예 here입니다) 제대로 작동 : 대답에 대한

var comboId = Ext.id(); 
new Ext.TabPanel({ 
    cls: 'tab-panel-with-combo', 
    renderTo: 'tab-with-combo', 
    activeTab: 0, 
    items:[ 
     { 
      title: '<div class="tab-title" style="float: left; padding-right: 5px;">First tab with a long name</div> ' + 
        '<div style="float: right;" id="' + comboId + '" ></div>', 
      closable: true, 
      html: 'Content of the first tab' 
     }, 
     { 
      title: '<div class="tab-title">Second tab</div>', 
      closable: true, 
      html: 'Content of the second tab' 
     } 
    ], 
    listeners: { 
     afterrender: function() { 
      var store = new Ext.data.ArrayStore({ 
       fields: ['abbr', 'case_name'], 
       data : [ 
        ['one', 'Case #1'], 
        ['two', 'Case #2'], 
        ['three', 'Case #3'] 
       ] 
      }); 

      new Ext.form.ComboBox({ 
       store: store, 
       displayField:'case_name', 
       editable: false, 
       typeAhead: false, 
       selectOnFocus:false, 
       mode: 'local', 
       forceSelection: true, 
       triggerAction: 'all', 
       emptyText:'Select a case...', 
       renderTo: comboId 
      }); 
     } 
    } 
}); 
3

답변 :

  1. Tabpanel 구성 요소가 preventDefault 탭을 클릭의 이벤트입니다, 그래서 우리는 onStripMouseDown 방법을 수정해야합니다.

  2. 우리가 title 속성에 무엇인가를 정의하면 extjs는 특별한 스타일을 가진 span.x-tab-strip-text html 요소에 넣을 것입니다. 따라서 우리는 콤보 박스를이 탭 다음에 추가해야합니다.

코드 : @ Alexander.Berg 답변

new Ext.TabPanel({ 
    renderTo : 'tab-with-combo', 
    activeTab : 0, 
    items : [{ 
      title : 'First tab ', 
      listeners : { 
       afterrender : function (panel) { 
        //the needed tabEl 
        var tabEl = panel.findParentByType('tabpanel').getTabEl(panel); 
        var tabStripInner = Ext.fly(tabEl).child('span.x-tab-strip-inner', true); 
        //we need that for have the combobox in the same line as the text 
        Ext.fly(tabStripInner).child('span.x-tab-strip-text', true).style.float = 'left'; 
        //create the combobox html element 
        var combo = document.createElement("select"); 
        var opt1 = document.createElement("option"); 
        opt1.innerHTML = 'Option 1'; 
        var opt2 = document.createElement("option"); 
        opt2.innerHTML = 'Option 2'; 
        combo.appendChild(opt1); 
        combo.appendChild(opt2); 
        combo.style.float = 'left';     
        //add the combobox to the tab 
        tabStripInner.appendChild(combo); 
       } 
      } 
     }, { 
      title : 'Second tab' 
     } 
    ], 

    //this is the tab's click handler 
    onStripMouseDown : function (e) { 
     if (e.button !== 0) { 
      return; 
     } 
     var t = this.findTargets(e); 
     if (t.close) { 
      //preventDefault needed to move here 
      e.preventDefault(); 
      if (t.item.fireEvent('beforeclose', t.item) !== false) { 
       t.item.fireEvent('close', t.item); 
       this.remove(t.item); 
      } 
      return; 
     } 
     if (t.item && t.item != this.activeTab) { 
      this.setActiveTab(t.item); 
     } 
    }, 
});
+0

감사합니다. 콤보를 동적으로 추가하는 것을 좋아하지만, 기본 private extjs 메서드를 변경하고 싶지는 않습니다.). 나는 당신의 예를 [여기] (http://jsfiddle.net/andron/4Evqr/)로 만들었습니다. 그것은 크롬에서는 작동하지만 FF (최신 23)에서는 작동하지 않습니다. – Andron

+0

BTW 내가 필요한 거의 모든 것을 다루는 또 다른 예를 만들었습니다. 그것을 확인하십시오 [여기] (http://jsfiddle.net/andron/GYxq8/2/). 하지만 추가 CSS 규칙 (제 경우에는 사용자 정의 테마 사용)과 div 래퍼 생성을 싫어합니다. 곧 답변을 업데이트하겠습니다. – Andron

관련 문제