以下内容中:fileList 为表格的id
1.编辑状态下无法获取实时的值【即编辑时候的值】
2.获取值都要先保存编辑状态 $("#fileList").jqGrid("saveRow",ids[i]);
3.赋值都要打开编辑状态 $("#fileList").jqGrid("editRow",ids[i]);
4.获取值
var record = $("#fileList").jqGrid("getRowData", rowId, true);
$("#fileList").jqGrid('getNodeParent',$("#fileList").jqGrid("getLocalRow", id)); //保存每次选中行父节点的数据
5.重写生成id的规则 【此方法是修改jqGrid源码方法】
$.jgrid.randId = function() { //重写jqGrid生成ID号规则。
return Math.random().toString(36).substr(21); //JS生成随机数
}
6.监听事件
//选中行监听事件
jQuery("#fileList").on("jqGridSelectRow", function(event, id, orgEvent) {
parentData = $("#fileList").jqGrid('getNodeParent',$("#fileList").jqGrid("getLocalRow", id)); //保存每次选中行父节点的数据
});
//新增修改 监听事件
/** frmgr 为新增的数据 */
jQuery("#fileList").on("jqGridAddEditAfterComplete",function(copydata, postdata, frmgr, frmoper){
/** 新增: 查看新增的节点是否有父节点, 有:父节点数据清空,且父节点不能编辑,自己可以编辑; 没有:自己可以编辑。 */
if(isHaveParent(frmgr.id)){ //有
var parent = $("#fileList").jqGrid('getNodeParent',$("#fileList").jqGrid("getLocalRow", frmgr.id)); //父节点数据
parent.startDate = null;
parent.endDate = null;
parent.examiner = null;
parent.comment = null;
$("#fileList").jqGrid("setTreeRow",parent.id,parent);
$("#fileList").jqGrid("saveRow",parent.id);
}
$("#fileList").jqGrid("editRow",frmgr.id);
});
//删除监听事件
/** 删除: 查看当前删除的节点的父节点下面还有没有子节点, 有:父节点不可以编辑; 没有:父节点可以编辑 */
jQuery("#fileList").on("jqGridDelRowAfterComplete",function(){
if(isHaveChildren(parentData.id)){
//$("#fileList").jqGrid("saveRow",parent.id);
}else{
$("#fileList").jqGrid("editRow",parentData.id);
}
});
7.ajax获取数据绑定数据
//获取数据
function getData(){
layer.load(2);
var url = "/Windchill/rest/ams/cert/getFileListTemplate";
//var url = "/Windchill/netmarkets/jsp/ext/ams/CERT/AC/fileList/data2.json";
$.ajax({
url:url,
type:"POST",
data:{
"type":"ac"
},
dataType:"json",
success:function(data){
for(var i in data ){
data[i].loaded = "true";
data[i].expanded = "true";
}
$("#fileList")[0].addJSONData(data);
$("#fileList").jqGrid("setGridParam",{datatype:"local"}); //*解决工具栏增删问题 【问题描述:绑定上数据之后,原来的添加,删除事件存在bug;如无法添加多层级】
startEdit();
layer.closeAll("loading");
},
error:function(data){
layer.closeAll("loading");
layer.msg(data,{time:other.layerMsgTime});
}
});
}
8.参考资料:
http://www.guriddo.net/demo/bootstrap/
9.jqGrid 树形表格多选参考
https://blog.csdn.net/zrk1000/article/details/46889455