plan2.jsp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 mydataP2,colName;
  5. $(document).ready( function() {
  6. loadNames(); //动态生成字段名称
  7. loadPlan2(); //加载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. $("#p2list").jqGrid("setGridWidth",document.body.clientWidth*0.48);
  13. });
  14. $(window).resize(function(){
  15. $("#p2list").jqGrid("setGridWidth",document.body.clientWidth*0.48);
  16. });
  17. //jqgrid初始化
  18. function loadPlan2(){
  19. jQuery("#p2list").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: "string"
  37. },
  38. {
  39. name: "BNAME",
  40. index: "BNAME",
  41. align: "center",
  42. sorttype: "string"
  43. },
  44. {
  45. name: "LWEIGHT",
  46. index: "LWEIGHT",
  47. align: "center",
  48. sorttype:"number",
  49. editable: true
  50. }
  51. ],
  52. cellEdit: true,
  53. cellsubmit: "clientArray", //当单元格发生变化后不直接发送请求、"remote"默认直接发送请求
  54. afterSaveCell: function(rowid,name,val,iRow,iCol) {
  55. var rowData = $("#p2list").jqGrid("getRowData",rowid);
  56. var currentpId = $("#currentpId").val();
  57. $.ajax({
  58. async: false,
  59. type: 'POST',
  60. dataType:'json', //返回类型jsond
  61. data: "ID="+rowData.ID+"&colValue="+val+"&currentpId="+currentpId,
  62. url: "${contextPath }/admin/recipeplan/dateplan2updatedyg.html",
  63. error: function(){alert("系统错误");},
  64. success: function(json){
  65. }
  66. });
  67. },
  68. footerrow: true, //统计运算的功能
  69. gridComplete: completeMethod,
  70. autowidth: true //自动调节宽度
  71. });
  72. //获取数据集
  73. mydataP2 = getPlan2();
  74. if(mydataP2!=null){
  75. for(var i=0;i<=mydataP2.length;i++){
  76. jQuery("#p2list").jqGrid('addRowData',i+1,mydataP2[i]);
  77. }
  78. }
  79. }
  80. //获取服务器数据
  81. function getPlan2(){
  82. var currentpId = $("#currentpId").val();
  83. $.ajax({
  84. async: false,
  85. type: 'POST',
  86. dataType:'json', //返回类型json
  87. url: "${contextPath }/admin/recipeplan/plan2list.html?currentpId="+currentpId,
  88. error: function(){alert("系统错误");},
  89. success: function(json){
  90. mydataP2 = json;
  91. }
  92. });
  93. return mydataP2;
  94. }
  95. //页脚统计
  96. function completeMethod(){
  97. var sum_lweight=$("#p2list").getCol("LWEIGHT",false,"sum");
  98. $("#p2list").footerData("set", {SORT:"合计:", LWEIGHT: sum_lweight.toFixed(2)});
  99. }
  100. //动态生成字段名称
  101. function loadNames(){
  102. var lpplanType = $("#lpplanType").val();
  103. if(lpplanType == 1){
  104. //如果是上料车
  105. colName = ["主键","操作序号", "发料车次","发料重量"]; //列名
  106. }else{
  107. //如果是混合、发料车
  108. colName = ["主键","操作序号", "舍栏编号","设计重量"]; //列名
  109. }
  110. }
  111. </script>
  112. <table id="p2list"></table>