js创建表格头部
var columns = [];
//获取column列属性
$.ajax({
url:workUrl+'/getColumnHeader',
data:{data:JSON.stringify({paramId:paramId})},
async:false,
type:'post',
dataType:'json',
success:function(data){
if(data.data != undefined && data.data != null ){
columns = [[ {
field : 'id',
title : 'id',
rowspan : 2,
width : 80,
sortable : true,
checkbox:true,
},{
field : 'worksetPonit',
title : '序号',
rowspan : 2,
width : 80,
align:'center',
sortable : true,
}],[]];
var c = data.data.pointdtoList;
for(var i = 0;i < c.length ;i++){
if(c[i].worksetEntryType == '1'){//值与偏差值列
columns[0].push({
title : c[i].paramCode +"["+c[i].conversionUnit+"]",
colspan : 2,
width : 160,
})
columns[1].push({
field : 'worksetValue01_'+i,
title : '值',
width : 80,
align : 'center',
dataColumn:true,
sortable : true,
editor: {
type:'text',
options:{
required:true
}
},
formatter:function(value,row,index){
if(value != null){
var i = this.field.split("_")[1];
row.pointdtoList[i].worksetValue01 = value;
return value;
}else {
var i = this.field.split("_")[1];
return row.pointdtoList[i].worksetValue01;
}
}
},
{
title: '偏差值',
field : 'worksetDeviationValue01_'+i,
width : 80,
align : 'center',
dataColumn:true,
sortable : true,
editor: {
type:'text',
options:{
required:true
}
},
formatter:function(value,row,index){
if(value != null){
var i = this.field.split("_")[1];
row.pointdtoList[i].worksetDeviationValue01 = value;
return value;
}else {
var i = this.field.split("_")[1];
return row.pointdtoList[i].worksetDeviationValue01;
}
}
});
}else{
columns[0].push({
title : c[i].paramCode +"["+c[i].conversionUnit+"]",
colspan : 1,
width : 80,
align : 'center',
})
columns[1].push({
field : 'worksetValue01_'+i,
title : '值',
width : 80,
align : 'center',
sortable : true,
dataColumn:true,
editor: {
type:'text',
options:{
required:true
}
},
formatter:function(value,row,index){
if(value != null){
var i = this.field.split("_")[1];
row.pointdtoList[i].worksetValue01 = value;
return value;
}else {
var i = this.field.split("_")[1];
return row.pointdtoList[i].worksetValue01;
}
}
});
}
}
}
}
})
初始化表格
$("#datagridId").datagrid({
url : url,
columns : columns
});
行编辑结束编辑保存时修改对应子表的数据
var rows = dg.datagrid('getChanges');
//处理主子表数据
for ( var i = 0; i < rows.length; i++) {
for(var key in rows[i]){
if(key.indexOf('worksetValue01') != -1){
var j = key.split("_")[1];
rows[i].pointdtoList[j].worksetValue01 = rows[i][key];
}else if(key.indexOf('worksetDeviationValue01') != -1){
var j = key.split("_")[1];
rows[i].pointdtoList[j].worksetDeviationValue01 = rows[i][key];
}
}
}