2015-09-02 159 views
0

我有一個使用與作爲結合於每個標籤的每個形式面板之間的的xtype插件共享相同的網格面板製表佈局的應用程序。標籤/ VBOX佈局

我的主要標籤佈局如下:

Ext.define('cardioCatalogQT.view.main.Main', { 
    extend: 'Ext.tab.Panel', 
    xtype: 'main-view', 
    controller: 'main-view', 
    requires: [ 
     'cardioCatalogQT.view.main.MainController', 
     'cardioCatalogQT.view.main.MainModel', 
     'Ext.ux.form.ItemSelector', 
     'Ext.tip.QuickTipManager', 
     'Ext.layout.container.Card' 
    ], 

    style: 'background-color:#dfe8f5;', 
    width: '100%', 
    height: 400, 

    layout: 'vbox', 
    defaults: { 
     bodyPadding: 5 
    }, 
    items: [{ 
      title:'Main', 
      region: 'south', 
      xtype: 'form', 
      itemId: 'Ajax', 
      flex: 1, 
      styleHtmlContent: true, 
      items:[{ 
       xtype: 'image', 
       src: 'resources/images/R3D3.png', 
       height: 50, 
       width: 280 
      },{ 
       title: 'Ad Hoc Sandbox for Cohort Discovery' 
      }] , 
      lbar:[{ 
       text: 'Initiate advanced request', 
       xtype: 'button', 

       handler: function(button){ 
        var url = 'https://url_here'; 
        //cardioCatalogQT.service.UtilityService.http_auth(button); 
        window.open(url); 
       } 
      }] 
     }, 
     /*{ 
      xtype: 'resultsGrid' 
      //disabled: true 
     },*/ 
     /*{ 
      xtype: 'searchGrid' 
      //disabled: true 
     },*/ 
     { 
      xtype: 'demographicGrid' 
      //disabled: true 
     }, 
     { 
      xtype: 'vitalGrid' 
      //disabled: true 
     }, 
     { 
      xtype: 'labGrid' 
      //disabled: true 
     }, 
     { 
      xtype: 'diagnosisGrid' 
      //disabled: true 

     }, 
     { 
      xtype: 'medicationGrid' 
      //disabled: true 
     }, 
     { 
      xtype: 'procedureGrid' 
      //disabled: true 
     }, 
     { 
      xtype: 'queryGrid' 
      //disabled: true 
     } 
    ] 
}); 

共享同一網格小部件(具體地,demographicGrid,vitalGrid,labGrid,diagnosisGrid,procedureGrid和medicationGrid各個標籤,每個標籤由的xtype在主引用查看)看起來像:

/** 
* Widget with template to render to Main view 
*/ 

Ext.define('cardioCatalogQT.view.grid.DemographicGrid', { 
    extend: 'Ext.form.Panel', 
    alias: 'widget.demographicGrid', 
    itemId: 'demographicGrid', 
    store: 'Payload', 

    requires: [ 
     'cardioCatalogQT.view.main.MainController' 
    ], 


    config: { 
     variableHeights: false, 
     title: 'Demographics', 
     xtype: 'form', 
     width: 200, 
     bodyPadding: 10, 
     defaults: { 
      anchor: '100%', 
      labelWidth: 100 
     }, 


     // inline buttons 
     dockedItems: [ { 
      xtype: 'toolbar', 
      height: 100, 
      items: [{ 
       xtype: 'button', 
       text: 'Constrain sex', 
       itemId: 'showSex', 
       hidden: false, 
       listeners: { 
        click: function (button) { 
         button.up('grid').down('#sexValue').show(); 
         button.up('grid').down('#hideSex').show(); 
         button.up('grid').down('#showSex').hide(); 
        } 
       } 
      }, { 
       xtype: 'button', 
       text: 'Hide sex constraint', 
       itemId: 'hideSex', 
       hidden: true, 
       listeners: { 
        click: function (button) { 
         button.up('grid').down('#sexValue').hide(); 
         button.up('grid').down('#sexValue').setValue(''); 
         button.up('grid').down('#hideSex').hide(); 
         button.up('grid').down('#showSex').show(); 
        } 
       } 
      },{ // Sex 
       xtype: 'combo', 
       itemId: 'sexValue', 
       queryMode: 'local', 
       editable: false, 
       value: 'eq', 
       triggerAction: 'all', 
       forceSelection: true, 
       fieldLabel: 'Select sex', 
       displayField: 'name', 
       valueField: 'value', 
       hidden: true, 
       store: { 
        fields: ['name', 'value'], 
        data: [ 
         {name: 'female', value: 'f'}, 
         {name: 'male', value: 'm'} 
        ] 
       } 
      }, { 
       xtype: 'button', 
       text: 'Constrain age', 
       itemId: 'showAge', 
       hidden: false, 
       listeners: { 
        click: function (button) { 
         button.up('grid').down('#ageComparator').show(); 
         button.up('grid').down('#ageValue').show(); 
         button.up('grid').down('#hideAge').show(); 
         button.up('grid').down('#showAge').hide(); 
        } 
       } 
      }, { 
       xtype: 'button', 
       text: 'Hide age', 
       itemId: 'hideAge', 
       hidden: true, 
       listeners: { 
        click: function (button) { 
         button.up('grid').down('#ageComparator').hide(); 
         button.up('grid').down('#ageValue').hide(); 
         button.up('grid').down('#upperAgeValue').hide(); 
         button.up('grid').down('#ageComparator').setValue(''); 
         button.up('grid').down('#ageValue').setValue(''); 
         button.up('grid').down('#upperAgeValue').setValue(''); 
         button.up('grid').down('#hideAge').hide(); 
         button.up('grid').down('#showAge').show(); 
        } 
       } 
      }, { // Age 
       xtype: 'combo', 
       itemId: 'ageComparator', 
       queryMode: 'local', 
       editable: false, 
       value: '', 
       triggerAction: 'all', 
       forceSelection: true, 
       fieldLabel: 'Select age that is', 
       displayField: 'name', 
       valueField: 'value', 
       hidden: true, 
       store: { 
        fields: ['name', 'value'], 
        data: [ 
         {name: '=', value: 'eq'}, 
         {name: '<', value: 'lt'}, 
         {name: '<=', value: 'le'}, 
         {name: '>', value: 'gt'}, 
         {name: '>=', value: 'ge'}, 
         {name: 'between', value: 'bt'} 
        ] 
       }, 

       listeners: { 
        change: function(combo, value) { 
         // use component query to toggle the hidden state of upper value 
         if (value === 'bt') { 
          combo.up('grid').down('#upperAgeValue').show(); 
         } else { 
          combo.up('grid').down('#upperAgeValue').hide(); 
         } 
        } 
       } 
      },{ 
       xtype: 'numberfield', 
       itemId: 'ageValue', 
       fieldLabel: 'value of', 
       value: '', 
       hidden: true 
      },{ 
       xtype: 'numberfield', 
       itemId: 'upperAgeValue', 
       fieldLabel: 'and', 
       hidden: true 
      },{ 
       xtype: 'button', 
       text: 'Constrain race/ethnicity', 
       itemId: 'showRace', 
       hidden: false, 
       listeners: { 
        click: function (button) { 
         button.up('grid').down('#raceValue').show(); 
         button.up('grid').down('#hideRace').show(); 
         button.up('grid').down('#showRace').hide(); 
        } 
       } 
      }, { 
       xtype: 'button', 
       text: 'Hide race/ethnicity constraint', 
       itemId: 'hideRace', 
       hidden: true, 
       listeners: { 
        click: function (button) { 
         button.up('grid').down('#raceValue').hide(); 
         button.up('grid').down('#raceValue').setValue(''); 
         button.up('grid').down('#hideRace').hide(); 
         button.up('grid').down('#showRace').show(); 
        } 
       } 
      },{ // Race 
       xtype: 'combo', 
       itemId: 'raceValue', 
       queryMode: 'local', 
       editable: false, 
       value: 'eq', 
       triggerAction: 'all', 
       forceSelection: true, 
       fieldLabel: 'Select race', 
       displayField: 'name', 
       valueField: 'value', 
       hidden: true, 
       store: { 
        fields: ['name', 'value'], 
        data: [ 
         {name: 'female', value: 'f'}, 
         {name: 'male', value: 'm'} 
        ] 
       } 
      },{ 
       //minWidth: 80, 
       text: 'Add to search', 
       xtype: 'button', 
       itemId: 'searchClick', 
       handler: 'onSubmitDemographics' 
      }] 
     }, 
      { 
       xtype:'searchGrid' 
      } 
     ] 

    } 


}); 

選項卡中每個窗體面板之間的唯一區別是項目組件。這些表單面板中的每一個都引用了一個「searchGrid」的xtype,並在附加圖像中呈現它:Tab rendered with searchGrid

問題是我有6個同一個網格的實例。這在很大程度上起作用,但它導致了一些與我的網格中的複選框控制以及一些離奇的網格存儲加載行爲有關的問題,並且老實說,使用這種反模式跟蹤組件是PITA。

我想以某種方式有我的searchGrid的單個實例在一個較低的垂直面板,而上垂直面板,我需要根據每個標籤的要求更改項目組件。項目控件如何變化的一個例子是Different panel with different item components

我希望的行爲是,當我點擊一個選項卡時,上面的項目組件會帶我到不同的窗體面板,而下面的面板保持固定在搜索網格上。

不過,我現在有綁定到每個選項卡的形式面板searchGrid,因爲這是我能得到這個工作的唯一途徑。

的searchGrid網格面板的樣子:

Ext.define('cardioCatalogQT.view.grid.Search', { 
    extend: 'Ext.grid.Panel', 

    xtype: 'framing-buttons', 
    store: 'Payload', 
    itemId: 'searchGrid', 

    requires: [ 
     'cardioCatalogQT.view.main.MainController' 
    ], 

    columns: [ 
     {text: "ID", width: 50, sortable: true, dataIndex: 'id'}, 
     {text: "Type", width: 120, sortable: true, dataIndex: 'type'}, 
     {text: "Key", flex: 1, sortable: true, dataIndex: 'key'}, 
     {text: "Criteria", flex: 1, sortable: true, dataIndex: 'criteria'}, 
     {text: "DateOperator", flex: 1, sortable: true, dataIndex: 'dateComparatorSymbol'}, 
     {text: "When", flex: 1, sortable: true, dataIndex: 'dateValue'}, 
     {text: "Count", flex: 1, sortable: true, dataIndex: 'n'} 
    ], 
    columnLines: true, 
    selModel: { 
     type: 'checkboxmodel', 
     listeners: { 
      selectionchange: 'onSelectionChange' 
     } 
    }, 

    // When true, this view acts as the default listener scope for listeners declared within it. 
    // For example the selectionModel's selectionchange listener resolves to this. 
    defaultListenerScope: false, 

    // This view acts as a reference holder for all components below it which have a reference config 
    // For example the onSelectionChange listener accesses a button using its reference 
    //referenceHolder: true, 

    // inline buttons 
    dockedItems: [{ 
     xtype: 'toolbar', 
     dock: 'bottom', 
     ui: 'footer', 
     layout: { 
      pack: 'center' 
     } 
    }, { 
     xtype: 'toolbar', 
     items: [{ 
      //reference: 'andButton', 
      text: 'AND', 
      itemId: 'andButton', 
      tooltip: 'Add the selected criteria as AND', 
      iconCls: 'and', 
      disabled: true, 
      handler: 'onCriterionAnd' 
     },'-',{ 
      //reference: 'orButton', 
      text: 'OR', 
      itemId: 'orButton', 
      tooltip: 'Add the selected criteria as OR', 
      iconCls: 'or', 
      disabled: true, 
      handler: 'onCriterionOr' 
     },'-',{ 
      //reference: 'notButton', 
      text: 'NOT', 
      itemId: 'notButton', 
      tooltip: 'Add the selected criteria as NOT', 
      iconCls: 'not', 
      disabled: true, 
      handler: 'onCriterionNot' 
     },'-',{ 
      //reference: 'removeButton', // The referenceHolder can access this button by this name 
      text: 'Remove', 
      itemId: 'removeButton', 
      tooltip: 'Remove the selected item', 
      iconCls: 'remove', 
      disabled: true, 
      handler: 'onCriterionRemove' 
     },'-', { // SaveQuery 
      //reference: 'SaveQuery', 
      text: 'Save', 
      itemId: 'saveQuery', 
      tooltip: 'save the current filter', 
      iconCls: 'save', 
      disabled: true, 
      handler: 'onFilterSave' 
     }] 
    }], 

    height: 1000, 
    frame: true, 
    iconCls: 'icon-grid', 
    alias: 'widget.searchGrid', 
    title: 'Search', 

    initComponent: function() { 
     this.width = 750; 
     this.callParent(); 
    } 
}); 

我用VBOX佈局讓我期望的行爲搞砸左右,但相當不成功。這看起來並不常見,通過一個Tab點擊將上面的Vbox面板更改爲不同的窗體面板,而較低的Vbox面板保持固定。任何見解都會受到歡迎。

+0

我建議有一個看一個邊界佈局有兩個地區'north'和'center'。 – Alexander

+0

我想我可能已經開始使用這個在第一個地方,由於房地產問題,而不是去標籤。我假設我需要隱藏/取消隱藏我的項目組件,以模仿在北部地區使用選項卡的行爲,而我的網格面板將位於中心區域? –

+0

不,不需要模仿任何東西,正如我剛剛發佈的答案中所見。 – Alexander

回答

1

如果我理解正確,我的這個小測試應該完全按照您的要求進行,使用區域northcenter的邊界佈局。 PS:我使用了ExtJS 4.2.2,但它也可以在其他Ext版本中使用。

+0

明白了!現在正在度假,但當我回來的時候會嘗試這個第一件事。非常感謝! –

+0

無法抗拒這一點。我認爲一些調整會起作用。網格工作不像我想要的那樣工作,但我確信我可以得到它。再次感謝!現在是時候享受我的假期了! –

+0

好吧,我需要將我的主視圖更改爲表單面板中的容器。奇蹟般有效! –