datadic.html 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Insert title here</title>
  6. <link rel="stylesheet" type="text/css" media="screen" href="${ctx}/assets/lib/jqueryui/jquery-ui.css" />
  7. <link rel="stylesheet" type="text/css" media="screen" href="${ctx}/assets/lib/jqgrid/css/ui.jqgrid.css" />
  8. <script type="text/ecmascript" src="${ctx}/assets/lib/jquery/1.9.1/jquery.min.js"></script>
  9. <script type="text/ecmascript" src="${ctx}/assets/lib/jqueryui/jquery-ui.js"></script>
  10. <script type="text/ecmascript" src="${ctx}/assets/lib/jqgrid/js/i18n/grid.locale-cn.js"></script>
  11. <script type="text/ecmascript" src="${ctx}/assets/lib/jqgrid/js/jquery.jqGrid.min.js"></script>
  12. <script type="text/javascript" src="${ctx}/assets/lib/layer/3.0.3/layer.js"></script>
  13. <script type="text/javascript">
  14. /**
  15. * 修改JSON中key的方法
  16. */
  17. function modifyJosnKey(json,oddkey,newkey){
  18. var val=json[oddkey];
  19. delete json[oddkey];
  20. json[newkey]=val;
  21. }
  22. $(function() {
  23. $("#tree").jqGrid({
  24. url : '${ctx}/myconsole/datadic/getByTree',
  25. editurl:"${ctx}/myconsole/datadic/saveOrUpdate2",
  26. mtype : "POST",
  27. "hoverrows":false,
  28. "viewrecords":false,
  29. "gridview":true,
  30. "height":"auto",
  31. //"loadonce":true,
  32. "rowNum":100,
  33. "scrollrows":true,
  34. // enable tree grid
  35. "treeGrid":true,
  36. // which column is expandable
  37. "ExpandColumn":"dicvalue",
  38. // datatype
  39. "treedatatype":"json",
  40. // the model used
  41. "treeGridModel":"adjacency",
  42. // configuration of the data comming from server
  43. "sortorder":"asc",
  44. autowidth : true,
  45. "datatype":"json",
  46. "pager":"#pager",
  47. prmNames : {
  48. id: "keyid", 
  49. oper:"oper",    
  50. addoper:"add",
  51. editoper:"edit",
  52. deloper:"del" 
  53. },
  54. colModel : [ {
  55. label : '字典名称',
  56. name : 'dicvalue',
  57. edittype : "text",
  58. editable: true,
  59. width : 100
  60. },{
  61. label : '编号',
  62. name : 'keyid',
  63. key : true,
  64. width : 75
  65. },{
  66. label : '树路径',
  67. name : 'treepath',
  68. editable : false,
  69. width : 120
  70. }, {
  71. label : '字典键值',
  72. name : 'dickey',
  73. edittype : "text",
  74. editable: true,
  75. width : 50
  76. },{
  77. label : '字典描述',
  78. name : 'dicdesc',
  79. editable: true,
  80. edittype : "textarea",
  81. editoptions: {
  82. size:50,
  83. maxlength: 500,
  84. rows:"10",
  85. cols:"40"
  86. }
  87. }, {
  88. label : '排序值',
  89. name : 'sortid',
  90. edittype : "text",
  91. editable: true,
  92. width : 30
  93. }, {
  94. label : '更新时间',
  95. name : 'updatetime',
  96. width : 50
  97. },{
  98. "name":"parentid",
  99. "hidden":true
  100. },{
  101. "name":"treelevel",
  102. "hidden":true
  103. } ],
  104. "treeReader":{
  105. "level_field":"treelevel",
  106. "leaf_field":"isleaf",
  107. "expanded_field":"expanded",
  108. "loaded":"loaded",
  109. "parent_id_field":"parentid",
  110. "icon_field":"icon"
  111. }
  112. });
  113. jQuery('#tree').jqGrid('navGrid','#pager',
  114. // the buttons to appear on the toolbar of the grid
  115. {
  116. edit : true,
  117. add : true,
  118. del : true,
  119. search : false,
  120. refresh : true,
  121. view : false,
  122. position : "left",
  123. cloneToTop : true
  124. },
  125. // options for the Edit Dialog
  126. {
  127. recreateForm : true,
  128. checkOnUpdate : true,
  129. checkOnSubmit : true,
  130. closeAfterEdit : true,
  131. serializeEditData: function(postdata) {
  132. //console.log(postdata);
  133. $.each(postdata,function (index, value) {
  134. if(index!="jqGrid_id" && index!="oper" && index!="id"){
  135. modifyJosnKey(postdata,index,"dataDic."+index);
  136. }
  137. if(index=="id"){
  138. postdata["dataDic."+index]=value
  139. }
  140. })
  141. //console.log(postdata);
  142. return postdata;
  143. },
  144. afterSubmit: function (response, postdata) {
  145. // console.log(response);
  146. var res=eval('(' + response.responseText + ')');
  147. //layer.msg(res.msg);
  148. return [res.state,res.msg,''];
  149. },
  150. errorTextFormat : function(data) {
  151. return 'Error: ' + data.responseText
  152. }
  153. },
  154. // options for the Add Dialog
  155. {
  156. closeAfterAdd : true,
  157. recreateForm : true,
  158. beforeSubmit: function(postdata, formid){
  159. var selRowId = $("#tree").jqGrid ('getGridParam', 'selrow');
  160. //console.log(selRowId);
  161. postdata.parentid=selRowId;
  162. if(postdata.parentid==null && postdata.parentid==""){
  163. postdata.parentid="0";
  164. }
  165. $.each(postdata,function (index, value) {
  166. if(index!="jqGrid_id" && index!="oper"){
  167. modifyJosnKey(postdata,index,"dataDic."+index);
  168. }
  169. })
  170. return[true,''];
  171. },
  172. afterSubmit: function (response, postdata) {
  173. //console.log(response.responseText);
  174. var res=eval('(' + response.responseText + ')');
  175. //layer.msg(res.msg);
  176. return [res.state,res.msg,''];
  177. },
  178. errorTextFormat : function(data) {
  179. return 'Error: ' + data.responseText
  180. }
  181. },
  182. // options for the Delete Dailog
  183. {
  184. errorTextFormat : function(data) {
  185. return 'Error: ' + data.responseText
  186. }
  187. });
  188. jQuery('#tree').jqGrid('bindKeys');
  189. })
  190. </script>
  191. </head>
  192. <body>
  193. <table id="tree"></table>
  194. <div id="pager"></div>
  195. </body>
  196. </html>