일부 파고 들자 원래 게시물의 코드와 내 자신의 코드를 모두 사용하여이 작업을 수행 할 수있는 방법을 찾았습니다. jqgrid 트리 그리드의 체크 상자를 클릭하면 노드의 부모와 노드의 부모가 동기화됩니다.
beforeSelectRow: function (rowid, e) {
var $this = $(this),
isLeafName = $this.jqGrid("getGridParam", "treeReader").leaf_field,
localIdName = $this.jqGrid("getGridParam", "localReader").id,
localData,
state,
parentState,
parentChildren,
setChechedStateOfChildrenItems = function (children) {
$.each(children, function() {
$("#" + this[localIdName] + " input.itmchk").prop("checked", state);
updateSelectedNode(row_id, this[localIdName], state);
if (!this[isLeafName]) {
setChechedStateOfChildrenItems($this.jqGrid("getNodeChildren", this));
}
});
},
setCheckedStateofParentItems = function (parent) {
parentChildren = $this.jqGrid("getNodeChildren", parent);
var selectedChildren = 0;
$.each(parentChildren, function() {
if ($("#" + this.id + " input.itmchk").prop("checked")) {
selectedChildren += 1;
}
});
if (selectedChildren == 0) {
parentState = false;
} else {
parentState = true;
}
updateSelectedNode(row_id, parent.id, parentState);
$("#" + parent.id + " input.itmchk").prop("checked", parentState);
if (parent.parent != null) {
setCheckedStateofParentItems($this.jqGrid("getLocalRow", parent.parent), state)
}
}
if (e.target.nodeName === "INPUT" && $(e.target).hasClass("itmchk")) {
state = $(e.target).prop("checked");
localData = $this.jqGrid("getLocalRow", rowid);
setChechedStateOfChildrenItems($this.jqGrid("getNodeChildren", localData), state);
setCheckedStateofParentItems($this.jqGrid("getLocalRow", localData.parent), state)
updateSelectedNode(row_id, localData.id, state); //this does the checkbox we checked
}
},
셀 포매터 부 :
{
name: 'name', width: 25, index: 'name', label: "ColumnName", labelAlign: "left",
formatter: function (cellvalue, options, rowObject) {
var result = "<input type='checkbox' class='itmchk' checked> " + $.jgrid.htmlEncode(cellvalue);
if (rowObject.selected == false) {
result = result.replace("checked", "");
}
return result;
}
}