pilot.jsp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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: "100%", //高度
  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: "DNAME",
  36. index: "DNAME",
  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: "teamGroup",
  48. index: "teamGroup",
  49. align: "center",
  50. sorttype: "string",
  51. editable: true,
  52. editrules:{
  53. required: true,
  54. custom: true,
  55. custom_func: checkName
  56. }
  57. },
  58. {
  59. name: "SORT",
  60. index: "SORT",
  61. align: "center",
  62. sorttype: "int",
  63. editable: true,
  64. editrules:{
  65. required: true,
  66. integer: true
  67. }
  68. },
  69. {
  70. name: "ENABLE",
  71. index: "ENABLE",
  72. align: "center",
  73. sorttype: "string",
  74. editable: true,
  75. edittype: "select",
  76. editoptions: {value:{"Yes":"是","No":"否"}}
  77. }
  78. ],
  79. caption: "驾驶员管理", //标题
  80. cellEdit: true,
  81. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  82. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  83. var rowData = $("#list").jqGrid("getRowData",rowid);
  84. $.ajax({
  85. async: false,
  86. type: "POST",
  87. dataType:"json", //返回类型jsond
  88. data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
  89. url: "${contextPath }/admin/basicdata/pilotupdatedyg.html",
  90. error: function(){alert("系统错误");},
  91. success: function(json){
  92. }
  93. });
  94. },
  95. pager: "#page", //#page分页控件绑定的位置对象
  96. rowNum: 100, //每页显示条数
  97. rowList: [100,200,300,400], //分页下拉选项内容
  98. rownumbers: true, //是否显示行数
  99. viewrecords: true, //是否显示总条数
  100. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  101. autowidth: true, //自动调节宽度
  102. sortname: "SORT", //按SORT进行排序 默认asc
  103. altRows: true, //设置表格是否允许行交替变色值
  104. altclass: "tdbgmouseover" //自定义隔行变色的样式
  105. });
  106. //获取数据集
  107. mydata = getLists();
  108. if(mydata!=null){
  109. for(var i=0;i<=mydata.length;i++){
  110. jQuery("#list").jqGrid("addRowData",i+1,mydata[i]);
  111. }
  112. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  113. }
  114. //绑定、设置工具栏
  115. jQuery("#list").jqGrid("navGrid","#page",{
  116. add: true, addtext: "添加",
  117. edit: false, edittext: "编辑",
  118. del: true, deltext: "删除",refresh: false,
  119. addfunc: addRow, //自定义添加方法
  120. delfunc: deleteRow, //自定义删除方法
  121. searchtext: "搜索",
  122. refreshtext: "刷新",
  123. alerttext:"请选择一条记录!"
  124. });
  125. }
  126. //获取服务器数据
  127. function getLists(){
  128. $.ajax({
  129. async: false,
  130. type: "POST",
  131. dataType:"json", //返回类型json
  132. url: "${contextPath }/admin/basicdata/pilotlist.html",
  133. error: function(){alert("系统错误");},
  134. success: function(json){
  135. mydata = json;
  136. }
  137. });
  138. return mydata;
  139. }
  140. //自定义添加方法
  141. function addRow(){
  142. var ids = $("#list").jqGrid("getDataIDs");
  143. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  144. $.ajax({
  145. async: false,
  146. type: "POST",
  147. dataType:"json", //返回类型jsond
  148. data: "oper=add&selId=",
  149. url: "${contextPath }/admin/basicdata/pilotupdate.html",
  150. error: function(){alert("系统错误");},
  151. success: function(json){
  152. $("#list").clearGridData(); //清空原grid数据
  153. loadList(); //重新载入服务器数据
  154. }
  155. });
  156. }
  157. //自定义删除方法
  158. function deleteRow(){
  159. var count = 0;
  160. var flag = confirm("您确定要删除吗?");
  161. if(flag){
  162. var row = $("#list").jqGrid("getGridParam","selrow");
  163. var selRow = $("#list").jqGrid("getRowData",row);
  164. $.ajax({
  165. async: false,
  166. type: "POST",
  167. dataType:"json", //返回类型jsond
  168. data: "selId="+selRow.ID,
  169. url: "${contextPath }/admin/basicdata/querypilotglxx.html",
  170. error: function(){alert("系统错误");},
  171. success: function(json){
  172. count = json.status;
  173. }
  174. });
  175. if(count == 0){
  176. $.ajax({
  177. async: false,
  178. type: "POST",
  179. dataType:"json", //返回类型jsond
  180. data: "oper=del&selId="+selRow.ID,
  181. url: "${contextPath }/admin/basicdata/pilotupdate.html",
  182. error: function(){alert("系统错误");},
  183. success: function(json){
  184. $("#list").clearGridData(); //清空原grid数据
  185. loadList(); //重新载入服务器数据
  186. }
  187. });
  188. }else{
  189. alert("该记录被引用、不能删除!!!");
  190. }
  191. }
  192. }
  193. //自定义验证名称是否存在方法
  194. function checkName(value, colname){
  195. var flag = 0;
  196. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  197. var rowData = $("#list").jqGrid("getRowData",selId); //获取当前选中行真实对象
  198. $.ajax({
  199. async: false,
  200. type: "POST",
  201. dataType: "json",
  202. data: "entityName="+value+"&type="+operType+"&entityId="+rowData.ID,
  203. url: "${contextPath}/admin/basicdata/pilotcheck.html",
  204. error: function(){alert("系统错误");},
  205. success: function(json){
  206. flag = json.status;
  207. }
  208. });
  209. if(flag == 0){
  210. return [true,""];
  211. }else{
  212. return [false,"名称已经存在!"];
  213. }
  214. }
  215. </script>
  216. </head>
  217. <body style="background-color: #E0E0E0">
  218. <div>
  219. <div class="navfrm">
  220. <span>当前位置:</span>
  221. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  222. <span>&nbsp;>>&nbsp;</span>
  223. <span>驾驶员管理</span>
  224. </div>
  225. <table id="list"></table>
  226. <div id="page"></div>
  227. </div>
  228. </body>
  229. </html>