表中显示的每周数据总数

时间:2017-09-25 04:11:14

标签: javascript jquery html html-table

我的桌子看起来像这样。现在我需要在每周行之后显示总测试和周期运行的总周数。有什么帮助吗?

目前表格如下:

<!DOCTYPE html>
<html>
  <head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
        .header-fixed {
            width: 100%
        }
        .table-fixed thead {
     }
.table-fixed tbody {
  height: 100%;
  width: 100%;
}
thead {
    position: fixed; 
}
 </style> 
 </head>
<body>

<div>
    <div class="modal-body">
        <div class="row">
            <div class="" style="width: 80%; margin: 0px auto">
                <table  class="table table-bordered header-fixed" style="border :1px">
                    <thead>
                    <tr style="background-color: #cdd0d6;">
                        <th style="width:10%;white-space: wrap;text-align: center;">ID</th> 
                        <th style="width:30%;white-space: nowrap;text-align: center;">Description</th>              
                        <th style="width:10%;white-space: wrap;text-align: center;">DoorNum</th>
                        <th style="width:10%;white-space: wrap;text-align: center;">First Name</th>
                        <th style="width:10%;white-space: wrap;text-align: center;">Num of ordered items</th>
                        <th style="width:30%;white-space: wrap;text-align: center;">Desc Comments</th>
                    </tr>
                    </thead>
                    <tbody >

                   <tr>
                        <td style="width:10%;text-align: center;">10</td>
                        <td style="width:30%;text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
                        <td style="width:10%;text-align: center; ">798</td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr> 
                     <tr>
                        <td style="width:10%;text-align: center;">20</td>
                        <td style="width:30%;text-align: center; "></td>
                        <td style="width:10%;text-align: center; ">798</td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr>
                     <tr>
                        <td style="width:10%;text-align: center;">30</td>
                        <td style="width:30%;text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
                        <td style="width:10%;text-align: center; "></td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr>
                     <tr>
                        <td style="width:10%;text-align: center;">40</td>
                        <td style="width:30%;text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
                        <td style="width:10%;text-align: center; ">798</td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr>
                     <tr>
                        <td style="width:10%;text-align: center;">50</td>
                        <td style="width:30%;text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
                        <td style="width:10%;text-align: center; ">798</td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr>
                     <tr>
                        <td style="width:10%;text-align: center;">60</td>
                        <td style="width:30%;text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
                        <td style="width:10%;text-align: center; ">798</td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr>

                     <tr>
                        <td style="width:10%;text-align: center;">70</td>
                        <td style="width:30%;text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
                        <td style="width:10%;text-align: center; ">798</td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr>

                     <tr>
                        <td style="width:10%;text-align: center;">8</td>
                        <td style="width:30%;text-align: center; ">Item belongs to Navvy modal 2014WE belomgs to the user name JOE dispathched after one week of odered date</td>
                        <td style="width:10%;text-align: center; ">798</td>
                        <td style="width:10%;text-align: center; ">Joe</td>
                        <td style="width:10%;text-align: center; ">4</td>
                        <td style="widtg:30%;text-align: center; ">Order dispatched</td>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>>
</body>
</html>

预期表应该是:

Week  Project     OS        TotalTests  #cycle of run 
    1     P1     Windows       0              0
          P2     Linux,UFO     4799           1

    2     P3     Windows       234           5

以下是代码:

 Week  Project     OS        TotalTests  #cycle of run 
    1     P1     Windows       0              1
          P2     Linux,UFO     4799           1
                   Total:      4799           2

    2     P3     Windows       234            5
                   Total:      234            5

1 个答案:

答案 0 :(得分:1)

在这种情况下,在循环中向后移动会使后来找到放置每个总行的位置变得更加复杂。在这里你有我的方法...

https://jsfiddle.net/rigobauer/959pthuk/

一条建议,处理和修改jQuery对象和DOM元素比javascript数组或字符串慢,所以考虑将它用于循环并最小化DOM操作。例如,而不是......

for (...) {
    let $tr = $('<tr/>');
    $tr.append("<td>" + data[i].Project + "</td>");
    $tr.append("<td>" + data[i].OS + "</td>");
    .....
    $('#GraphTable').prepend($tr);
}

...使用......

let rows = [];
for (...) {
    let row = '<tr>' +;
              '<td>' + data[i].Project + '</td>' +
              '<td>' + data[i].OS + '</td>';
    .....
              '</tr>';
    rows.push(row);
}
$('#GraphTable').prepend(rows.join(''));

根据循环的大小,它可以更快。

当你需要求和时,记得把你的字符串转换成数字......

Total = Total + parseInt(data[i].CycleRun);

我希望它有所帮助