ext异步请求动态设置列头

在项目中遇到个呕心的设计,GIRD列头根据表数据动态的去取,所以就需要动态加载表格列头,下面代码就是动态设置表格列头重新加载GRID

 

/**
 * <p>Title: 下网侧系统</p>
 * <p>Description: 下网侧系统</p>
 * <p>Copyright: Copyright (c) 2009</p>
 * <p>Company: 江苏方天电力技术有限公司</p>
 * ============================================================
 * 功能描述:电量上报 异步请求来设置列头
 * ============================================================
 * 更新时间:2010.04.23
 * 更新人:古军益
 * 更新内容:新建
 * ============================================================
 */
com.frontier.sec.secbasedata.energyData.meterCmHeaderMethod = function() {
 
 com.frontier.sec.secbasedata.energyData.meterCmHeader = []
 var cmResultArray =new Array();
  com.frontier.sec.secbasedata.energyData.rangeTypeValue =1;
 if(Ext.getCmp('rangeTypeStation')){
    com.frontier.sec.secbasedata.energyData.rangeType = Ext.getCmp('rangeTypeStation').getValue();
 };
 Ext.Ajax.request({
  url:gdc.webContextRoot + 'energyData/findMeterDateCmAction.action',
  params:{
   'voltID' : com.frontier.sec.secbasedata.energyData.voltID,
   'stationID':+com.frontier.sec.secbasedata.energyData.stationID,
   'queryType':com.frontier.sec.secbasedata.energyData.nodeType,
   'rangeType':com.frontier.sec.secbasedata.energyData.rangeTypeValue,
   'ammeterType':com.frontier.sec.secbasedata.energyData.ammeterTypeStationValue
  },
  success:function(response){
   var meterCm =new Array(); 
   var limit = 8;
   var cmResult = Ext.util.JSON.decode(response.responseText).cmHeader; 
   if(cmResult !=null){
    cmResultArray  = cmResult.split(',');
    com.frontier.sec.secbasedata.energyData.totalCounter = cmResultArray.length;
     var gridPanelStation = Ext.getCmp('meterSearchStationGrid');
            gridPanelStation.getStore().removeAll();
          gridPanelStation.getStore().load();
    meterCm.push(new Ext.grid.RowNumberer());
   meterCm.push({
       header :Ext.util.Format.htmlEncode(cmResultArray[0]),
    dataIndex : 'dataShow0',
    id:'dataShow',
    width : 100,
    sortable : false,
    align:'center',
    menuDisabled :true,
    renderer:function(value) {
      var renderValue = value;
      return renderValue;
    }
   });
   for (var i = 1; i < cmResultArray.length; i++) {
    if(i<limit) {
    meterCm.push({
     header :"<a href= '#' onclick=com.frontier.sec.secbasedata.energyData.devWindowLinkClick("+(i+1)+",'"+cmResultArray[i]+"')>"+Ext.util.Format.htmlEncode(cmResultArray[i])+"</a>" ,
     dataIndex : 'dataShow'+i,
     width : 100,
     align:'center',
     menuDisabled :true,
     renderer:function (v,p,record,rowIndex,colIndex,store){
      var arrayStr = v.split(':');
      return com.frontier.sec.secbasedata.showDataStauts.showTipMeterDataStatus(arrayStr[0],p,record,rowIndex,colIndex,store,arrayStr[1],"meterSearchStationGrid");
    }});
    } else {
     meterCm.push({
                    header :"<a href= '#' onclick=com.frontier.sec.secbasedata.energyData.devWindowLinkClick("+(i+1)+",'"+cmResultArray[i]+"')>"+Ext.util.Format.htmlEncode(cmResultArray[i])+"</a>" ,
     dataIndex : 'dataShow'+i,
     width : 100,
     align:'center',
     hidden:true,
     menuDisabled :true,
     renderer:function (v,p,record,rowIndex,colIndex,store){
      var arrayStr = v.split(':');
      return com.frontier.sec.secbasedata.showDataStauts.showTipMeterDataStatus(arrayStr[0],p,record,rowIndex,colIndex,store,arrayStr[1],"meterSearchStationGrid");
        }
    });
    }
   }
   Ext.getCmp('meterSearchStationGrid').getColumnModel().setConfig(meterCm);
   }
  }
 });
}

//

隔了好久没注释,有空加上,谅解~

 

 

 

你可能感兴趣的:(function,header,ext,null,url,2010)