明细表隐藏任意明细列,控制明细列明细字段必填只读,新增删除明细行显示不全,表单页面抖动,明细表分页,完美版
<script>
jQuery(document).ready(function () {
jQuery(".sh").addClass("detail_hide_col"); //sh 隐藏列class 属性,默认隐藏 detail_hide_col 泛微自带列隐藏属性
WfForm.bindFieldChangeEvent("field53408", function (obj, id, value) { //field53408 主表字段
var arr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
for (var i = 0; i < arr.length; i++) {
if (value == 0) { //field53408 主表字段的值
WfForm.changeFieldAttr("field53410_" + arr[i], 1); //field53410 明细字段的值
jQuery(".sh").addClass("detail_hide_col");
} else {//当选择显示全部列
//显示之前被隐藏的列
WfForm.changeFieldAttr("field53410_" + arr[i], 3);
jQuery(".sh").removeClass("detail_hide_col");
}
}
});
WfForm.registerAction(WfForm.ACTION_ADDROW + "1", function (index) {
var value = WfForm.getFieldValue("field53408"); //field53408 主表字段的值
if (value == 1) { //field53408 主表字段的值
//显示之前被隐藏的列
WfForm.changeFieldAttr("field53410_" + index, 3);
jQuery(".sh").removeClass("detail_hide_col");
} else {//隐藏全部列
WfForm.changeFieldAttr("field53410_" + index, 1);
jQuery(".sh").addClass("detail_hide_col");
}
});
})
</script>
优化版:
jQuery(document).ready(function () {
var hideColumns = function () {
jQuery(".sh").toggleClass("detail_hide_col", jQuery("#field53408").val() == 0);
};
WfForm.bindFieldChangeEvent("field53408", function (obj, id, value) {
var arr = WfForm.getDetailAllRowIndexStr("detail_1").split(",");
arr.forEach(function (index) {
WfForm.changeFieldAttr("field53410_" + index, value == 0 ? 1 : 3);
});
hideColumns();
});
WfForm.registerAction(WfForm.ACTION_ADDROW + "1", function (index) {
var value = WfForm.getFieldValue("field53408");
WfForm.changeFieldAttr("field53410_" + index, value == 1 ? 3 : 1);
hideColumns();
});
});