2015-09-02 204 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

好吧,我需要将我的主视图更改为表单面板中的容器。奇迹般有效! –