pagination.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. const rowsPerPage = 15;
  2. let currentPage = 1;
  3. function populateTable(j_data,channel_power) {
  4. i = 0
  5. channel_data_length = channel_power.length
  6. const tableBody = document.getElementById('tbody');
  7. tableBody.innerHTML = ''; // 清空表格体
  8. const startIndex = (currentPage - 1) * rowsPerPage;
  9. const endIndex = startIndex + rowsPerPage;
  10. const pageData = channel_power.slice(startIndex, endIndex);
  11. // 创建一个新的列表项元素
  12. const listItem = document.createElement('tr');
  13. //自动生成设备名称列
  14. const Device_name_td = document.createElement('td');
  15. Device_name_td.textContent = "Smart PDU"
  16. Device_name_td.rowSpan = 3
  17. listItem.appendChild(Device_name_td);
  18. // pageData.forEach(item => {
  19. // i++
  20. // j = channel_data_length / 3
  21. // // 创建一个新的列表项元素
  22. // const listItem = document.createElement('tr');
  23. // //自动生成设备名称列
  24. // const Device_name_td = document.createElement('td');
  25. // Device_name_td.textContent = "Smart PDU"
  26. // listItem.appendChild(Device_name_td);
  27. // //自动生成通道名称列
  28. // const Chananl_name_td = document.createElement('td');
  29. // Chananl_name_td.textContent = "CH"+j+"-"+"L"+i
  30. // listItem.appendChild(Chananl_name_td);
  31. // //自动生成通道名称列
  32. // const Chananl_num_td = document.createElement('td');
  33. // Chananl_num_td.textContent = j
  34. // listItem.appendChild(Chananl_num_td);
  35. // //自动生成相序列
  36. // const xiangxu_td = document.createElement('td');
  37. // xiangxu_td.textContent = "L"+i
  38. // listItem.appendChild(xiangxu_td);
  39. // // 自动生成电压列
  40. // const voltage_td = document.createElement('td');
  41. // voltage_data = item.voltage.toFixed(2);
  42. // if(voltage_data <= 0)
  43. // {
  44. // voltage_data = 0
  45. // }
  46. // voltage_td.textContent = voltage_data
  47. // listItem.appendChild(voltage_td);
  48. // // 自动生成电流列
  49. // const current_td = document.createElement('td');
  50. // current_data = item.current.toFixed(2);
  51. // if(current_data <= 0)
  52. // {
  53. // current_data = 0
  54. // }
  55. // current_td.textContent = current_data;
  56. // listItem.appendChild(current_td);
  57. // // 自动生成功率列
  58. // const power_td = document.createElement('td');
  59. // power_data = item.power.toFixed(2);
  60. // if(power_data <= 0)
  61. // {
  62. // power_data = 0
  63. // }
  64. // power_td.textContent = power_data
  65. // listItem.appendChild(power_td);
  66. // // 自动生成频率列
  67. // const freq_td = document.createElement('td');
  68. // freq_data = item.power.toFixed(2);
  69. // if(freq_data <= 0)
  70. // {
  71. // freq_data = 0
  72. // }
  73. // freq_td.textContent = freq_data
  74. // listItem.appendChild(freq_td);
  75. // // 自动生成耗电量列
  76. // const consump_td = document.createElement('td');
  77. // consump_data = item.consump.toFixed(2);
  78. // if(consump_data <= 0)
  79. // {
  80. // consump_data = 0
  81. // }
  82. // consump_td.textContent = consump_data
  83. // listItem.appendChild(consump_td);
  84. // // 自动生成功率因数列
  85. // const factor_td = document.createElement('td');
  86. // factor_data = item.factor.toFixed(2);
  87. // if(factor_data <= 0)
  88. // {
  89. // factor_data = 0
  90. // }
  91. // factor_td.textContent = factor_data
  92. // listItem.appendChild(factor_td);
  93. // // 自动生成开启延时列
  94. // const open_td = document.createElement('td');
  95. // open_td.textContent = 0;
  96. // listItem.appendChild(open_td);
  97. // // 自动生成关闭延时列
  98. // const close_td = document.createElement('td');
  99. // close_td.textContent = 0;
  100. // listItem.appendChild(close_td);
  101. // // 自动生成状态列
  102. // const status_td = document.createElement('td');
  103. // channel_status = item.status
  104. // listItem.appendChild(status_td);
  105. // if(channel_status == 1)
  106. // {
  107. // status_td.textContent = '接通';
  108. // // 自动生成关闭按钮列
  109. // const close_button_td = document.createElement('button');
  110. // close_button_td.textContent = '关闭';
  111. // close_button_td.id = `Button_close_ ${i}`;
  112. // close_button_td.addEventListener('click', function() {
  113. // const userConfirmed = confirm('是否确定关闭该通道');
  114. // if (userConfirmed) {
  115. // single_close(j_data,channel_power_infro,channel_infro)
  116. // } else {
  117. // alert('已取消关闭通道');
  118. // }
  119. // });
  120. // listItem.appendChild(close_button_td);
  121. // }else{
  122. // status_td.textContent = '断开';
  123. // // 自动生成开启按钮列
  124. // const open_button_td = document.createElement('button');
  125. // open_button_td.id = `Button_open_ ${i}`;
  126. // open_button_td.textContent = '开启';
  127. // open_button_td.addEventListener('click', function() {
  128. // const userConfirmed = confirm('是否确定开启该通道');
  129. // if (userConfirmed) {
  130. // single_open(j_data,channel_power_infro,channel_infro)
  131. // } else {
  132. // alert('已取消开启通道');
  133. // }
  134. // });
  135. // listItem.appendChild(open_button_td);
  136. // }
  137. // // 自动生成输出类型列
  138. // const input_type_td = document.createElement('td');
  139. // input_type_td.textContent = '三相';
  140. // listItem.appendChild(input_type_td);
  141. // tableBody.appendChild(listItem);
  142. // });
  143. // updatePagination(channel_data_length)
  144. }
  145. function updatePagination(totalRows) {
  146. totalRows = channel_data_length
  147. const pagination = document.getElementById('page2_pagination');
  148. pagination.innerHTML = ''; // 清空表格体
  149. const totalPages = Math.ceil(totalRows / rowsPerPage);
  150. for (let i = 1; i <= totalPages; i++) {
  151. const button = document.createElement('button');
  152. button.style.width = "5%";
  153. button.style.height = "100%";
  154. button.textContent = i;
  155. button.disabled = i === currentPage; // 禁用当前页按钮(可选)
  156. button.onclick = () => {
  157. currentPage = i;
  158. populateTable(channel_power);
  159. updatePagination(totalRows, rowsPerPage); // 重新渲染分页按钮以反映当前页码(可选,但推荐)
  160. };
  161. pagination.appendChild(button);
  162. }
  163. }