formatter使用
1. formatter 文法結構
單元格formatter(格式化器)函數,帶3個參數:
value:字段值。
row:行記錄資料。
index: 行索引。
代碼示例:
$('#dg').datagrid({
columns:[[
{field:'name',title:'名稱', width:80,
formatter: function(value,row,index){
if (row.code=='1001'){
return val;
} else {
return null;
}
}
}
]]
});
- formatter 加樣式 代碼
formatter: function (cellvalue) {
if (cellvalue == "合格") {
return "<span style='color:green'>合格</span>";
} else if (cellvalue == "不合格") {
return "<span style='color:red'>不合格</span>";
}
}
- 實作樣式
- formatter 指派代碼
{
label: '實際工時', name: 'f_abilitytime', width: 100, align: 'center'
, edit: {
type: 'input',//輸入式編輯
},
formatter: function (cellvalue, row) {
if (cellvalue != "" || cellvalue=="0") {
return cellvalue;
} else if (cellvalue == "") {
row.f_abilitytime = jqtime;
return jqtime;
}
},
},