extjs 동적 생성grid

2493 단어 EXTJSextjs동적grid
/**
* grid grid
* author :zyj
* @param {} v format: key1:val1,key2:val2...;,key11:val11,key22:val22...;...
* @param {} elId ID
*/
function vToGrid(v,elId) {
var cmItems = [new Ext.grid.RowNumberer()];
var record=v.split(";")
var headerTmp= record[0].split(",");
var fields=[];
for(var i=0;i var htmp=headerTmp[i].split(":");
if((htmp[0].indexOf('ID')==-1)&&(htmp[0].indexOf(' ')==-1)){
cmConfig = {
header: headerTmp[i].split(":")[0],
tooltip:headerTmp[i].split(":")[0],
dataIndex: 'indexTmp'+i,
sortable: true ,
renderer:function(value){
return '
'+value+'
';
}
};
fields.push('indexTmp'+i)
cmItems.push(cmConfig);
}

}
var cm = new Ext.grid.ColumnModel(cmItems);
var sqldata = new Array();
for (var t = 0; t < record.length; t++) {
if(!(record[t]==null||record[t]==''||record[t].length==0)){
var recordTmp= record[t].split(",");
var oneData = new Array();
for(var tt=0;tt if(recordTmp[tt].indexOf(":")!=-1){
var ttmp=recordTmp[tt].split(":");
if((ttmp[0].indexOf("ID")==-1)
&&(ttmp[0].indexOf(" ")==-1)){
if(ttmp.length=2){
oneData.push(ttmp[1]);
}else{
oneData.push(" ");
}
}
}

}
sqldata.push(oneData);
}

}
var store = new Ext.data.SimpleStore({
fields:fields
});

store.loadData(sqldata);
var gd = new Ext.grid.GridPanel({
renderTo : elId,
cm : cm,
width : '98%',
store : store,
region:'center',
trackMouseOver : true,
disableSelection : false,
loadMask : true,
autoHeight : true,
viewConfig : {
// autoFill : true, //
forceFit : true,
scrollOffset: 0 // , grid ,
//showPreview : false
},
stripeRows: true,//
bodyStyle : 'width:100%;',
align : 'center'
});
}

좋은 웹페이지 즐겨찾기