plan1.jsp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <%@ page contentType="text/html; charset=utf-8" session="false" %>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <script type="text/javascript">
  4. var mydataP1,colName;
  5. $(document).ready( function() {
  6. loadNames(); //动态生成字段名称
  7. loadPlan1(); //加载jqgrid
  8. panelC = $("body").layout("panel","center").panel();
  9. panelSHeight = document.body.clientHeight - panelC.height();
  10. $("#p1list").jqGrid("setGridHeight",panelSHeight-130);
  11. $("#p2list").jqGrid("setGridHeight",panelSHeight-130);
  12. $("#p1list").jqGrid("setGridWidth",document.body.clientWidth*0.49);
  13. });
  14. $(window).resize(function(){
  15. $("#p1list").jqGrid("setGridWidth",document.body.clientWidth*0.49);
  16. });
  17. //jqgrid初始化
  18. function loadPlan1(){
  19. jQuery("#p1list").jqGrid({
  20. datatype: "local", //从服务器端返回的数据类型,(表格期望接收的数据类型)。可选类型:xml,xmlstring,json,local,function
  21. height: 150, //高度
  22. colNames: colName,
  23. colModel:[
  24. {
  25. name: "ID",
  26. index: "ID",
  27. width: 1,
  28. align: "center",
  29. sorttype: "string",
  30. hidden: true
  31. },
  32. {
  33. name: "SORT",
  34. index: "SORT",
  35. align: "center",
  36. sorttype: "int"
  37. },
  38. {
  39. name: "Fname",
  40. index: "Fname",
  41. align: "center",
  42. sorttype: "string"
  43. },
  44. {
  45. name: "LWEIGHT",
  46. index: "LWEIGHT",
  47. align: "center",
  48. sorttype:"number",
  49. editable: true,
  50. formatter:"number",
  51. summaryType:"sum"
  52. },
  53. {
  54. name: "L1",
  55. index: "L1",
  56. align: "center",
  57. sorttype:"number"
  58. }
  59. ],
  60. cellEdit: true,
  61. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  62. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  63. var rowData = $("#p1list").jqGrid("getRowData",rowid);
  64. var currentpId = $("#currentpId").val();
  65. $.ajax({
  66. async: false,
  67. type: 'POST',
  68. dataType:'json', //返回类型jsond
  69. data: "ID="+rowData.ID+"&colValue="+val+"&currentpId="+currentpId,
  70. url: "${contextPath }/admin/recipeplan/dateplan1updatedyg.html",
  71. error: function(){alert("系统错误");},
  72. success: function(json){
  73. }
  74. });
  75. },
  76. grouping: true,
  77. groupingView: {
  78. groupField: ["SORT"],
  79. groupSummary: [true],
  80. groupText: ["操作序号[{0}]小计"],
  81. groupCollapse: false
  82. },
  83. rowNum: 1000, //每页显示条数
  84. footerrow: true, //统计运算的功能
  85. gridComplete: completeMethod,
  86. autowidth: true //自动调节宽度
  87. });
  88. //获取数据集
  89. mydataP1 = getPlan1();
  90. if(mydataP1!=null){
  91. for(var i=0;i<=mydataP1.length;i++){
  92. jQuery("#p1list").jqGrid('addRowData',i+1,mydataP1[i]);
  93. }
  94. jQuery("#p1list").jqGrid("sortGrid","SORT"); //手动让某字段排序
  95. }
  96. }
  97. //获取服务器数据
  98. function getPlan1(){
  99. var currentpId = $("#currentpId").val();
  100. $.ajax({
  101. async: false,
  102. type: 'POST',
  103. dataType:'json', //返回类型json
  104. url: "${contextPath }/admin/recipeplan/plan1list.html?currentpId="+currentpId,
  105. error: function(){alert("系统错误");},
  106. success: function(json){
  107. mydataP1 = json;
  108. }
  109. });
  110. return mydataP1;
  111. }
  112. //页脚统计
  113. function completeMethod(){
  114. var sum_lweight=$("#p1list").getCol("LWEIGHT",false,"sum");
  115. $("#p1list").footerData("set", {SORT:"合计:", LWEIGHT: sum_lweight.toFixed(2)});
  116. }
  117. //动态生成字段名称
  118. function loadNames(){
  119. var lpplanType = $("#lpplanType").val();
  120. if(lpplanType == 2){
  121. //如果是发料车
  122. colName = ["主键","操作序号","需加料","加料重量","加料重量合计"]; //列名
  123. }else{
  124. //如果是混合、上料车
  125. colName = ["主键","操作序号","饲料名称","设计重量","同序号设计重量合计"]; //列名
  126. }
  127. }
  128. </script>
  129. <table id="p1list"></table>