29d2e93c7982c944fe006f05ff7b664f91a46d0a.svn-base 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>父子表</title>
  6. <!--框架必需start-->
  7. <script type="text/javascript" src="../../libs/js/jquery.js"></script>
  8. <script type="text/javascript" src="../../libs/js/language/cn.js"></script>
  9. <script type="text/javascript" src="../../libs/js/framework.js"></script>
  10. <link href="../../libs/css/import_basic.css" rel="stylesheet" type="text/css"/>
  11. <link rel="stylesheet" type="text/css" id="skin" prePath="../../"/>
  12. <link rel="stylesheet" type="text/css" id="customSkin"/>
  13. <!--框架必需end-->
  14. <!--数据表格start-->
  15. <script src="../../libs/js/table/quiGrid.js" type="text/javascript"></script>
  16. <!--数据表格end-->
  17. </head>
  18. <body>
  19. <div class="red">此示例由后台支持</div>
  20. 这里实现了新增时默认读取父表对应行的部门名称,新增、修改和删除时只刷新当前展开的子表。
  21. <div class="padding_right5">
  22. <div id="maingrid"></div>
  23. </div>
  24. <script type="text/javascript">
  25. //设定不可编辑的节点id
  26. var noeditArray = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"];
  27. var grid;
  28. var gridArray=[];
  29. function initComplete(){
  30. /*
  31. grid = $("#maingrid").quiGrid({
  32. columns: [
  33. { display: 'ID', name: 'orgId', align: 'left',width:50},
  34. { display: '部门名称', name: 'orgName' ,width:200},
  35. { display: '部门描述', name: 'orgDescription' ,width:200},
  36. { display: '负责人', name: 'orgManager' ,width:200},
  37. { display: '联系电话', name: 'orgPhone',width:200 },
  38. { display: '部门父ID', name: 'parentId' ,width:100}
  39. ],
  40. //isScroll:false表示不出现滚动条,高度自适应。 frozen:false表示列宽不固定,可通过拖拽进行调整。
  41. frozen:false,url: '../../organizationAction.do?method=getGridData',width:'100%',height:'100%',
  42. detail: { onShowDetail: showEmployees, height: 'auto' },
  43. onError: function (a, b){
  44. //错误事件
  45. }
  46. });
  47. */
  48. };
  49. //显示所选部门下的员工
  50. function showEmployees(row, detailPanel,callback){
  51. var childGrid = document.createElement('div');
  52. $(detailPanel).append(childGrid);
  53. var childGrid=$(childGrid).css('margin',10).quiGrid({
  54. columns: [
  55. { display: '姓名', name: 'userName', align: 'left'},
  56. { display: '所属部门', name: 'orgName', align: 'left'},
  57. { display: '性别', name: 'userSex', align: 'left'},
  58. { display: '入职时间', name: 'userEmployTime', align: 'left'} ,
  59. { display: '学历', name: 'userEducation', align: 'left'} ,
  60. { display: '操作', isAllowHide: false, align: 'left',
  61. render: function (rowdata, rowindex, value, column){
  62. return '<div class="padding_top4 padding_left5">'
  63. + '<span class="img_list hand" title="查看" onclick="onView(' + rowdata.userId + ')"></span>'
  64. + '<span class="img_edit hand" title="修改" onclick="onEdit(' + rowdata.userId + ','+row.orgId+')"></span>'
  65. + '<span class="img_delete hand" title="删除" onclick="onDelete(' + rowdata.userId+','+rowindex + ','+row.orgId+')"></span>'
  66. + '</div>';
  67. }
  68. }
  69. ],
  70. sortName: 'userId',width: '95%', columnWidth: 120,height:230,
  71. url: '../../userAction.do?method=getUsers&parentId=' + row.orgId,
  72. pageSize: 5,
  73. toolbar:{
  74. items:[
  75. {text: '新增', click: function(){addUnit(row.orgId)}, iconClass: 'icon_add'},
  76. { line : true },
  77. {text: '批量删除', iconClass: 'icon_delete'},
  78. { line : true },
  79. {text: '导入', iconClass: 'icon_import'},
  80. { line : true },
  81. {text: '导出当前页', iconClass: 'icon_export'},
  82. { line : true },
  83. {text: '导出全部', iconClass: 'icon_export'}
  84. ]
  85. }
  86. });
  87. var obj={};
  88. obj.id=row.orgId;
  89. obj.grid=childGrid;
  90. gridArray.push(obj);
  91. }
  92. //新增
  93. function addUnit(orgid) {
  94. top.Dialog.open({
  95. URL:"../../sample_html/datagrid/user-management-content-detailGrid.html?orgid=" + orgid+"&gridId="+orgid,
  96. Title:"添加",Width:500,Height:350});
  97. }
  98. //查看
  99. function onView(rowid){
  100. top.Dialog.open({
  101. URL:"../../userAction.do?method=getUserDetail&userinfor.userId=" + rowid,
  102. Title:"查看",Width:500,Height:350});
  103. }
  104. //修改
  105. function onEdit(rowid,gridId){
  106. if (getPosition(rowid, noeditArray) != -1) {
  107. top.Dialog.alert("为保证数据的完整性,由管理员添加的数据无法修改或删除。可以为新添加的数据来修改和删除。");
  108. return false;
  109. }
  110. top.Dialog.open({
  111. URL:"../../sample_html/datagrid/user-management-contentAjax-detailGrid.html?userId=" + rowid+"&gridId="+gridId,
  112. Title:"修改",Width:500,Height:350});
  113. }
  114. //删除
  115. function onDelete(rowid,rowidx,gridId){
  116. if (getPosition(rowid, noeditArray) != -1) {
  117. top.Dialog.alert("为保证数据的完整性,由管理员添加的数据无法修改或删除。可以为新添加的数据来修改和删除。");
  118. return false;
  119. }
  120. top.Dialog.confirm("确定要删除该记录吗?",function(){
  121. //删除记录
  122. $.post("../../userAction.do?method=deleteUser",
  123. {"ids":rowid},
  124. function(result){
  125. handleResult(result,gridId);
  126. },"json");
  127. });
  128. }
  129. //删除后的提示
  130. function handleResult(result,gridId){
  131. if(result == 1){
  132. top.Dialog.alert("删除成功!",null,null,null,1);
  133. //只刷新当前子表
  134. var childGrid;
  135. $.each(gridArray,function(idx,item){
  136. if(item.id==gridId){
  137. childGrid=item.grid;
  138. }
  139. })
  140. childGrid.loadData();
  141. }else{
  142. top.Dialog.alert("删除失败!");
  143. }
  144. }
  145. //只刷新当前子表
  146. function refreshChild(isUpdate,gridId){
  147. var childGrid;
  148. $.each(gridArray,function(idx,item){
  149. if(item.id==gridId){
  150. childGrid=item.grid;
  151. }
  152. })
  153. if(childGrid){
  154. if(!isUpdate){
  155. //重置排序
  156. childGrid.options.sortName='userId';
  157. childGrid.options.sortOrder="desc";
  158. //页号重置为1
  159. childGrid.setNewPage(1);
  160. }
  161. childGrid.loadData();
  162. }
  163. }
  164. </script>
  165. </body>
  166. </html>