数据样式
对表格中的选取的数据进行样式设置。
列如:
在列名中设置styler:ageStyle
<th data-options="field:'age',width:70,editor:'textbox',styler:ageStyle">年龄</th>
在js中agestyle
function ageStyle(value,row,index){
if(value <=23){
return 'background- color:red;color:black;';
}else if(value>=27){
return 'background-color:green;color:black;';
}
}
ageStyle()方法中,方法名字可以自定义,但是参数是固定的。
value 字段值
row 行记录数据(行的对象)
index 行的索引值
return 返回样式(对单元格中的数据)数据格式化
对表格中的选取的数据进行格式化设置。
列如:
在列名中设置formatter:sexFormatter
<th data-options="field:'sex',width:40,formatter:sexFormatter">性别</th>
在js中sexFormatter
function sexFormatter(value,row,index){ if(value=='男'){
return 1;
}else{
return 0;
}
}
sexFormatter()方法中,方法名字可以自定义,但是参数是固定的。
value 字段值
row 行记录数据(行的对象)
index 行的索引值
return 返回数据(对单元格中的数据)
需要添加列时的处理
<th data-options="field:'tel',title:'userInfo',width:40,formatter:telFormatter">电话</th>
function telFormatter(value,row,index){
//alert(row.userInfo);
return row.userInfo.tel;
}
当某列获取到对象时,获取该对象成员的方法。
value 字段值
row 行记录数据(行的对象)
index 行的索引值
return 返回数据(对单元格中的数据)