cattle.jsp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <%@ page contentType="text/html; charset=utf-8" session="false" %>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
  4. <head>
  5. <title>我的工作台</title>
  6. <%@ include file="../common/header.jsp" %>
  7. <script type="text/javascript">
  8. var mydata,operType;
  9. $(document).ready( function() {
  10. loadList(); //加载jqgrid
  11. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  12. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  13. });
  14. $(window).resize(function(){
  15. $("#list").jqGrid("setGridHeight",$(window).height() - 105);
  16. $("#list").jqGrid("setGridWidth",document.body.clientWidth - 5);
  17. });
  18. //jqgrid初始化
  19. function loadList(){
  20. jQuery("#list").jqGrid({
  21. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  22. height: "70%", //高度
  23. colNames:['主键','牲畜类别名称','顺序', '是否启用'], //列名
  24. colModel:[
  25. {
  26. name: "ID",
  27. index: "ID",
  28. align: "center",
  29. sorttype: "string",
  30. editable: true,
  31. hidden: true
  32. //editoptions:{readonly:true} 如果要显示该列可以设置只读
  33. },
  34. {
  35. name: "CLASSNAME",
  36. index: "CLASSNAME",
  37. align: "center",
  38. sorttype: "string",
  39. editable: true,
  40. editrules:{
  41. required: true,
  42. custom: true,
  43. custom_func: checkName
  44. }
  45. },
  46. {
  47. name: "SORT",
  48. index: "SORT",
  49. align: "center",
  50. sorttype: "int",
  51. editable: true,
  52. editrules:{
  53. required: true,
  54. integer: true
  55. }
  56. },
  57. {
  58. name: "ENABLE",
  59. index: "ENABLE",
  60. align: "center",
  61. sorttype: "string",
  62. editable: true,
  63. edittype: "select",
  64. editoptions: {value:{"Yes":"是","No":"否"}}
  65. }
  66. ],
  67. caption: "牲畜类别管理", //标题
  68. cellEdit: true,
  69. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  70. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  71. var rowData = $("#list").jqGrid("getRowData",rowid);
  72. $.ajax({
  73. async: false,
  74. type: 'POST',
  75. dataType:'json', //返回类型jsond
  76. data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
  77. url: "${contextPath }/admin/basicdata/cattleupdatedyg.html",
  78. error: function(){alert("系统错误");},
  79. success: function(json){
  80. }
  81. });
  82. },
  83. pager: "#page", //#page分页控件绑定的位置对象
  84. rowNum: 100, //每页显示条数
  85. rowList: [100,200,300,400], //分页下拉选项内容
  86. rownumbers: true, //是否显示行数
  87. viewrecords: true, //是否显示总条数
  88. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  89. autowidth: true, //自动调节宽度
  90. sortname: "SORT", //按SORT进行排序 默认asc
  91. altRows: true, //设置表格是否允许行交替变色值
  92. altclass: "tdbgmouseover" //自定义隔行变色的样式
  93. });
  94. //获取数据集
  95. mydata = getLists();
  96. if(mydata!=null){
  97. for(var i=0;i<=mydata.length;i++){
  98. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  99. }
  100. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  101. }
  102. //绑定、设置工具栏
  103. jQuery("#list").jqGrid("navGrid","#page",{
  104. add: true, addtext: "添加",
  105. edit: false, edittext: "编辑",
  106. del: true, deltext: "删除",refresh: false,
  107. addfunc: addRow, //自定义添加方法
  108. delfunc: deleteRow, //自定义删除方法
  109. searchtext: "搜索",
  110. refreshtext: "刷新",
  111. alerttext:"请选择一条记录!"
  112. });
  113. }
  114. //获取服务器数据
  115. function getLists(){
  116. $.ajax({
  117. async: false,
  118. type: 'POST',
  119. dataType:'json', //返回类型json
  120. url: "${contextPath }/admin/basicdata/cattlelist.html",
  121. error: function(){alert("系统错误");},
  122. success: function(json){
  123. mydata = json;
  124. }
  125. });
  126. return mydata;
  127. }
  128. //自定义添加方法
  129. function addRow(){
  130. var ids = $("#list").jqGrid("getDataIDs");
  131. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  132. $.ajax({
  133. async: false,
  134. type: "POST",
  135. dataType:"json", //返回类型jsond
  136. data: "oper=add&selId=",
  137. url: "${contextPath }/admin/basicdata/cattleupdate.html",
  138. error: function(){alert("系统错误");},
  139. success: function(json){
  140. $("#list").clearGridData(); //清空原grid数据
  141. loadList(); //重新载入服务器数据
  142. }
  143. });
  144. }
  145. //自定义删除方法
  146. function deleteRow(){
  147. var count = 0;
  148. var flag = confirm("您确定要删除吗?");
  149. if(flag){
  150. var row = $("#list").jqGrid("getGridParam","selrow");
  151. var selRow = $("#list").jqGrid("getRowData",row);
  152. $.ajax({
  153. async: false,
  154. type: "POST",
  155. dataType:"json", //返回类型jsond
  156. data: "selId="+selRow.ID,
  157. url: "${contextPath }/admin/basicdata/querycattleglxx.html",
  158. error: function(){alert("系统错误");},
  159. success: function(json){
  160. count = json.status;
  161. }
  162. });
  163. if(count == 0){
  164. $.ajax({
  165. async: false,
  166. type: "POST",
  167. dataType:"json", //返回类型jsond
  168. data: "oper=del&selId="+selRow.ID,
  169. url: "${contextPath }/admin/basicdata/cattleupdate.html",
  170. error: function(){alert("系统错误");},
  171. success: function(json){
  172. $("#list").clearGridData(); //清空原grid数据
  173. loadList(); //重新载入服务器数据
  174. }
  175. });
  176. }else{
  177. alert("该记录被引用、不能删除!!!");
  178. }
  179. }
  180. }
  181. //自定义验证名称是否存在方法
  182. function checkName(value, colname){
  183. var flag = 0;
  184. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  185. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  186. $.ajax({
  187. async: false,
  188. type: 'POST',
  189. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
  190. dataType: 'json',
  191. url: "${contextPath}/admin/basicdata/cattlecheck.html",
  192. error: function(){alert("系统错误");},
  193. success: function(json){
  194. flag = json.status;
  195. }
  196. });
  197. if(flag == 0){
  198. return [true,""];
  199. }else{
  200. return [false,"牲畜类别已经存在!"];
  201. }
  202. }
  203. </script>
  204. </head>
  205. <body style="background-color: #E0E0E0">
  206. <div>
  207. <div class="navfrm">
  208. <span>当前位置:</span>
  209. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  210. <span>&nbsp;>>&nbsp;</span>
  211. <span>牲畜类别管理</span>
  212. </div>
  213. <table id="list"></table>
  214. <div id="page"></div>
  215. </div>
  216. </body>
  217. </html>