pluslpplan.jsp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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:["主键","车次","TMR","驾驶员","描述","生效","重量","配方模版"], //列名
  24. colModel:[
  25. {name: "ID",index: "ID",width: 1,align: "center",sorttype: "string",hidden: true},
  26. {name: "SORT",index: "SORT",width: 50,align: "center",sorttype: "int",editable: true,editrules: {integer: true}},
  27. {name: "TNAME",index: "TNAME",width: 70,align: "center",sorttype: "int",editable: true,edittype: "select",
  28. editoptions:{
  29. dataUrl: "${contextPath }/admin/recipeplan/tmrselect.html",
  30. dataEvents: [{
  31. type: "change", fn: function(e){
  32. var selId = $("#list").jqGrid("getGridParam","selrow"); //获取当前选中行号
  33. var thisval = $(e.target).val();
  34. if(thisval != ""){
  35. $.ajax({
  36. async: false,
  37. type: "post",
  38. dataType: "json", //返回类型json
  39. data: "tmrId="+thisval,
  40. url: "${contextPath }/admin/recipeplan/getDnameByTmrId.html",
  41. error: function(){alert("系统错误");},
  42. success: function(json){
  43. if(json.status == "success"){
  44. $("#list").setCell(selId,"DNAME",json.DNAME);
  45. }
  46. }
  47. });
  48. }else{
  49. $("#list").setCell(selId,"DNAME"," ");
  50. }
  51. }
  52. }]
  53. }
  54. },
  55. {name: "DNAME",index: "DNAME",width: 70,align: "center",sorttype: "int",editable: true,edittype: "select",editoptions:{dataUrl: "${contextPath }/admin/recipeplan/pilotselect.html"}},
  56. {name: "remark",index: "remark",width: 70,align: "center",sorttype: "string",editable: true},
  57. {name: "Sel",index: "Sel",width: 70,align: "center",sorttype: "string",editable: true,edittype: "select",editoptions: {value:{"1":"是","0":"否"}}},
  58. {name: "sumWeight",index: "sumWeight",width: 70,align: "center",sorttype: "string",editable: true},
  59. {name: "templetName",index: "templetName",width: 70,align: "center",sorttype: "string",editable: true,edittype: "select",editoptions:{dataUrl: "${contextPath }/admin/recipeplan/templetselect.html"}}
  60. ],
  61. caption: "补料计划", //标题
  62. cellEdit: true,
  63. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  64. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  65. var rowData = $("#list").jqGrid("getRowData",rowid);
  66. $.ajax({
  67. async: false,
  68. type: 'POST',
  69. dataType:'json', //返回类型jsond
  70. data: "ID="+rowData.ID+"&colName="+name+"&colValue="+val,
  71. url: "${contextPath }/admin/recipeplan/plpdatedyg.html",
  72. error: function(){alert("系统错误");},
  73. success: function(json){
  74. }
  75. });
  76. },
  77. pager: "#page", //#page分页控件绑定的位置对象
  78. rowNum: 1000, //每页显示条数
  79. rowList: [100,200,300,400], //分页下拉选项内容
  80. rownumbers: true, //是否显示行数
  81. viewrecords: true, //是否显示总条数
  82. emptyrecords: "无数据", //服务器返回空列表时显示的内容
  83. autowidth: true, //自动调节宽度
  84. sortname: 'SORT', //按SORT进行排序 默认asc
  85. altRows: true, //设置表格是否允许行交替变色值
  86. altclass:"tdbgmouseover" //自定义隔行变色的样式
  87. });
  88. //获取数据集
  89. mydata = getLists();
  90. if(mydata!=null){
  91. for(var i=0;i<=mydata.length;i++){
  92. jQuery("#list").jqGrid('addRowData',i+1,mydata[i]);
  93. }
  94. jQuery("#list").jqGrid().trigger("reloadGrid"); //添加完数据后客户端自动刷新一次、实现客户端数据与服务器数据的完全分离
  95. }
  96. //绑定、设置工具栏
  97. jQuery("#list").jqGrid("navGrid","#page",{
  98. add: true, addtext: "添加",
  99. edit: false, edittext: "编辑",
  100. del: true, deltext: "删除",refresh: false,search: false,
  101. addfunc: addRow, //自定义添加方法
  102. delfunc: deleteRow, //自定义删除方法
  103. searchtext: "搜索",
  104. refreshtext: "刷新",
  105. alerttext:"请选择一条记录!"
  106. });
  107. }
  108. //获取服务器数据
  109. function getLists(){
  110. $.ajax({
  111. async: false,
  112. type: 'POST',
  113. dataType:'json', //返回类型json
  114. url: "${contextPath }/admin/recipeplan/pluslpplanlist.html",
  115. error: function(){alert("系统错误");},
  116. success: function(json){
  117. mydata = json;
  118. }
  119. });
  120. return mydata;
  121. }
  122. //自定义添加方法
  123. function addRow(){
  124. var ids = $("#list").jqGrid("getDataIDs");
  125. $("#list").jqGrid("addRowData",ids.length+1,{},"first");
  126. $.ajax({
  127. async: false,
  128. type: "POST",
  129. dataType:"json", //返回类型jsond
  130. data: "oper=add&selId=",
  131. url: "${contextPath }/admin/recipeplan/pluslpplanupdate.html",
  132. error: function(){alert("系统错误");},
  133. success: function(json){
  134. $("#list").clearGridData(); //清空原grid数据
  135. loadList(); //重新载入服务器数据
  136. }
  137. });
  138. }
  139. //自定义删除方法
  140. function deleteRow(){
  141. var row = $("#list").jqGrid("getGridParam","selrow");
  142. if(row!=null){
  143. var flag = confirm("您确定要删除吗?");
  144. if(flag){
  145. var selRow = $("#list").jqGrid("getRowData",row);
  146. $.ajax({
  147. async: false,
  148. type: "POST",
  149. dataType:"json", //返回类型jsond
  150. data: "oper=del&selId="+selRow.ID,
  151. url: "${contextPath }/admin/recipeplan/pluslpplanupdate.html",
  152. error: function(){alert("系统错误");},
  153. success: function(json){
  154. $("#list").clearGridData(); //清空原grid数据
  155. loadList(); //重新载入服务器数据
  156. }
  157. });
  158. }
  159. }else{
  160. alert("请选择记录");
  161. }
  162. }
  163. </script>
  164. </head>
  165. <body style="background-color: #E0E0E0">
  166. <div>
  167. <div class="navfrm">
  168. <span>当前位置:</span>
  169. <span><a href="${contextPath }/admin/welcome.html">首页</a></span>
  170. <span>&nbsp;>>&nbsp;</span>
  171. <span>补料计划</span>
  172. </div>
  173. <table id="list"></table>
  174. <div id="page"></div>
  175. </div>
  176. </body>
  177. </html>