GridPanel中添加动态列

//根据传入时间参数,动态添加列var sd=params.sTime;
   var ed=params.eTime;

   var sy=sd.substr(0,4);
   var ey=ed.substr(0,4);
   
   var sm=Number(sd.substr(5,7));
   var em=Number(ed.substr(5,7));
   
   var count=12*(ey-sy)+(em-sm)+1;
   
   var dates=[];  
   
   var colModelTem =new Ext.grid.ColumnModel([
                   new Ext.grid.RowNumberer(),
                   new Ext.grid.CheckboxSelectionModel(),
      {
                    header : "往来单位",
     dataIndex : 'customerAll',
     sortable : true,
     width: 200,
     align : 'left'
                   },{
                    header : "合计",
              dataIndex : 'totalMoney',
              sortable : true,
              align : 'left'
                   },{
                    header : "多开发票金额",
     dataIndex : 'invoicedMoney',
     sortable : true,
     align : 'left'
               }
                ]);
   
   var fields = ['customerAll','totalMoney','invoicedMoney'];
   
   //往数组里添加日期
   for(var i=0;i<count;i++){
    var months=parseInt(sm+i);
    if(months>12){
     var year=parseInt((sm+i)/12);
     var month=parseInt((sm+i)%12);
     dates[i]=(sy+year)+'-'+month;
     colModelTem.addColumn(dates[i],3+i);
     fields.push(dates[i]);
    }else{
     dates[i]=sy+"-"+months;
     colModelTem.addColumn(dates[i],3+i);
     fields.push(dates[i]);
    }
   }  
    //var json = this.getJsonDate(params);

    var storeTem  = new Ext.data.JsonStore({
     autoLoad : true,
     url : 'viewUnInvoiceSummaryItem',
     remoteSort : true,
     root : 'json.data',
     totalProperty : 'json.totalCount',
     fields : fields,
     sortInfo : {
      field : 'id',
      direction : 'DESC'
       },
       baseParams : {
       start : 0,
       limit : commonPageSize,
       customerAll : params.customerAll,
                   sTime : params.sTime,
                   eTime : params.eTime 
     }
        });
    this.reconfigure(storeTem,colModelTem);

你可能感兴趣的:(json,ext)