日期:2014-05-16  浏览次数:20468 次

Extjs gridpanel中动态生存ColumnModel为什么就不能够显示列能!有源码供参考!
为什么我动态生成ColumnModel不会显示列呢?虽然列不能够显示 但是里面的数据还是能够显示,并且也是动态有多少列就显示了多少列,请教大家帮忙一下,希望各位大侠的解答和帮助。谁帮我解决了,我请你糖哦!嘻嘻……
备注:resMess为我后台返回的报文,这个报文包含了我要显示的表头(显示列)和grid里面要显示的数据。
function ReportListShow(resMess){
    var tempStr = setMessage(resMess);
    if(getFieldValue(tempStr,"erorcd",0).trim()=='0000'){
        scrollBar.hide();
        if(Str == "outExecl"){
            return Ext.MessageBox.alert('提示','导出Excel成功!',function(){
                 location = "../ExportExcle.jsp?filename="+reportName+"&operid="+Fuserid;
            }); 
        }
        var oneStr = resMess.indexOf('[');
        if(oneStr == -1){
            return Ext.MessageBox.alert('提示','查询结果为空!');
        }
        var twoStr = resMess.substring(0,oneStr);        //第一张表记录(包含表头和对应的字段)
        var threeStr = resMess.substring(oneStr + 1);
        
        var frouStr = threeStr.indexOf('[');
        var fiveStr = threeStr.substring(0,frouStr);    //第二张表记录(包含页数)
        var tempStrs = setMessage(fiveStr);
        contPages = getFieldValue(tempStrs,"totalnumber",0);
        countPage.setText(contPages);
        document.getElementById('page').value = m;
        if(parseInt(contPages) > 1){
            downPage.enable();
        }
        
        var sixStr = threeStr.substring(frouStr + 1);    //第三张表记录(报表信息数据)
        var tableData = getParsing(setMessArray0(sixStr));
        if(tableData != null){
            execlRept.enable();
        }else if(tableData == null){
            return Ext.MessageBox.alert('提示','对不起!您输入的参数值无信息返回!');
        }
        var tableHeadData = setMessArray(twoStr);        //截取表头字符串

        var gridHeader = [tableHeadData.length-1];
        var readerFildeName = [tableHeadData.length-1];
        for(var a=0;a<tableHeadData.length;a++){
            if(a==0){
                gridHeader[a] = '[{header:"'+tableHeadData[a][1]+'",sortable:true,dataIndex:"'+tableHeadData[a][0].toLowerCase()+'"}';
                readerFildeName[a] = '[{name:"'+tableHeadData[a][0].toLowerCase()+'",mapping:'+a+'}';
            }else if(a==tableHeadData.length-1){
                gridHeader[a] = '{header:"'+tableHeadData[a][1]+'",sortable:true,dataIndex:"'+tableHeadData[a][0].toLowerCase()+'"}]';
                readerFildeName[a] = '{name:"'+tableHeadData[a][0].toLowerCase()+'",mapping:'+a+'}]';
            }else{
                gridHeader[a] = '{header:"'+tableHeadData[a][1]+'",sortable:true,dataIndex:"'+tableHeadData[a][0].toLowerCase()+'"}';
                readerFildeName[a] = '{name:"'+tableHeadData[a][0].toLowerCase()+'",mapping:'+a+'}';
            }
        }
        
        var cm = new Ext.grid.ColumnModel(gridHeader);
        var readerstext = Ext.data.Record.create(readerFildeName);
        var repDefStore = new Ext.data.Store({
            proxy:new Ext.data.MemoryProxy(tableData),
            reader:new Ext.data.ArrayReader({},readerstext)
        })
        repDefStore.load();
            
        var repDefGrid = new Ext.grid.GridPanel({
            renderTo:'repShow'+(index),
            cm:cm,
            store:repDefStore,
            loadMask:{msg:'数据正在加载中……'},
            autoHeight:true
        });
        
    }else if(getFieldValue(tempStr,"erorcd",0).trim()=='9000'){
        scrollBar.hide();
        return Ext.MessageBox.alert('查询失败',getFieldValue(tempStr,"erortx",0));
    }
}
 
 
 
 
对我有用[0] 丢个板砖[0] 引用 举报 管理 TOP 回复次数:0  
1 楼 liwu556677 2010-07-20  
我以解决了此问题关键代码我把它贴出来和大家一起分享:
gridHeader = [new Ext.grid.RowNumberer(),new Ext.grid.CheckboxSelectionModel()];
		readerFildeName = [];
		for(var a=0;a<tableHeadData.length;a++){
			gridHeader.push({
				header:tableHeadData[a][1],
				dataIndex:tableHeadData[a][0].toLowerCase(),
				sortable:true,
				renderer:gridFontColor,
				width:160
			})
			r