Extjs Column布局常见问题及解决方法

from:http://blog.csdn.net/weoln/article/details/4339533

第一次用Extjs的column布局时遇见了很多问题,记录下来,供大家参考。column布局时常会碰见label不能显示或者控件显示错位等问题,导致这些问题的常见原因如下:

1.formPanel上的控件显示不出来,控件的宽度太大,formpanel的宽度相对太小导致。

2.FormPanel设定了defaultType属性,没有为每个控件单独制定xtype属性。正确的做法是不设置defaultType。

3.在每个column里再加上form layout,再在form里加textfield。

4.在新建TabPanel时,将其属性layoutOnTabChange设置为true即可。(此方法不通用)

实例代码如下:

  
  
  
  
  1. Ext.onReady(function(){   
  2.             Ext.QuickTips.init();   
  3.    
  4.     // turn on validation errors beside the field globally   
  5.     Ext.form.Field.prototype.msgTarget = 'side';   
  6.    
  7.     var bd = Ext.getBody();   
  8.    
  9. var detailForm = new Ext.FormPanel({   
  10.         id:"detail",   
  11.         layout:"form",   
  12.         labelWidth: 60,   
  13.         labelAlign:"right",   
  14.         border:false,   
  15.         frame:true,   
  16.         width: 600,//宽度设置要合理,如果FormPanel的宽度小于控件的宽度,column布局时控件不能正常显示   
  17.         height:400,   
  18. //      autoHeight:true,   
  19. //      defaultType: 'textfield',//column布局时不能设置该属性,否则不能正常显示   
  20.         items: [{//第一行   
  21.             layout:"column",   
  22.             items:[{   
  23.                 columnWidth:.3,//第一列   
  24.                 layout:"form",   
  25.                 items:[{   
  26.                     xtype:"textfield",   
  27.                     fieldLabel: '合同编号',   
  28.                     name: 'contractId',   
  29.                     width:100   
  30.                     }]   
  31.             },{   
  32.                 columnWidth:.3,//第二列   
  33.                 layout:"form",   
  34.                 items:[{   
  35.                     xtype:"combo",   
  36.                     fieldLabel: '合同名称',   
  37.                     name: 'contractId1',   
  38.                     width:100   
  39.                     }]   
  40.             },{   
  41.                 columnWidth:.3,//第三列   
  42.                 layout:"form",   
  43.                 items:[{   
  44.                     xtype:"textfield",   
  45.                     fieldLabel: '合同',   
  46.                     name: 'contractId2',   
  47.                     width:100   
  48.                     }]   
  49.             }]},//第一行结束   
  50.             {//第一行   
  51.             layout:"column",   
  52.             items:[{   
  53.                 columnWidth:.3,//第一列   
  54.                 layout:"form",   
  55.                 items:[{   
  56.                     xtype:"textfield",   
  57.                     fieldLabel: '合同编号',   
  58.                     name: 'contractId',   
  59.                     width:100   
  60.                     }]   
  61.             },{   
  62.                 columnWidth:.3,//第二列   
  63.                 layout:"form",   
  64.                 items:[{   
  65.                     xtype:"textfield",   
  66.                     fieldLabel: '合同名称',   
  67.                     name: 'contractId1',   
  68.                     width:100   
  69.                     }]   
  70.             },{   
  71.                 columnWidth:.3,//第三列   
  72.                 layout:"form",   
  73.                 items:[{   
  74.                     xtype:"textfield",   
  75.                     fieldLabel: '合同',   
  76.                     name: 'contractId2',   
  77.                     width:100   
  78.                     }]   
  79.             }]},//第一行结束   
  80.             {//第一行   
  81.             layout:"column",   
  82.             items:[{   
  83.                 columnWidth:.3,//第一列   
  84.                 layout:"form",   
  85.                 items:[{   
  86.                     xtype:"textfield",   
  87.                     fieldLabel: '合同编号',   
  88.                     name: 'contractId',   
  89.                     width:100   
  90.                     }]   
  91.             },{   
  92.                 columnWidth:.3,//第二列   
  93.                 layout:"form",   
  94.                 items:[{   
  95.                     xtype:"textfield",   
  96.                     fieldLabel: '合同名称',   
  97.                     name: 'contractId1',   
  98.                     width:100   
  99.                     }]   
  100.             },{   
  101.                 columnWidth:.3,//第三列   
  102.                 layout:"form",   
  103.                 items:[{   
  104.                     xtype:"textfield",   
  105.                     fieldLabel: '合同',   
  106.                     name: 'contractId2',   
  107.                     width:100   
  108.                     }]   
  109.             }]}//第一行结束   
  110.            ]   
  111.       });    
  112.    
  113.    
  114.    
  115. var win =  new  Ext.Window(   
  116.                {   
  117.                 id:"window",   
  118.                 title: " 合同信息 " ,   
  119.                 layout: 'border',   
  120.                 width:600,   
  121.                 height:500,   
  122.                 closeAction:'hide',   
  123.                 plain: true,   
  124.                    
  125.                 items:[new Ext.TabPanel({   
  126.                         region: 'center',   
  127.                         deferredRender: false,   
  128. //                      layoutOnTabChange:true,//在TabPanel中采用column布局时,有时需要设置该属性   
  129.                         activeTab: 0, //活动的tab索引   
  130.                         items: [{   
  131.                             //contentEl: 'tab1',   
  132.                             title: '合同明细',   
  133.                             closable: false//关闭项   
  134.                             autoScroll: false//是否自动显示滚动条   
  135.                             layout:'fit',   
  136.                             collapsible: true,   
  137.                             split:true,   
  138.                             margins:'0 0 0 0',   
  139.                             items:[detailForm]   
  140.                         },{   
  141.                             //contentEl: 'tab2',   
  142.                             title: '规格明细',   
  143.                             closable: false//关闭项   
  144.                             autoScroll: false//是否自动显示滚动条   
  145.                             layout:'fit',   
  146.                             collapsible: true,   
  147.                             split:true,   
  148.                             margins:'0 0 0 0'   
  149.                         }]   
  150.                     })],   
  151.                    
  152.                 buttons: [{   
  153.                     text:'Submit',   
  154.                     disabled:true   
  155.                 },{   
  156.                     text: 'Close',   
  157.                     handler: function(){   
  158.                         win.hide();   
  159.                        // detailForm.destroy();   
  160.                     }   
  161.                 }]   
  162.    
  163.       });       
  164.       
  165.     //显示窗口   
  166.     win.show();   
  167.    
  168. });   

 

 

 

 

 

 

你可能感兴趣的:(职场,ExtJs,休闲)