【发布时间】:2021-10-29 05:31:46
【问题描述】:
它是一个从 php 获取数据的简单表格
<table style="margin-right: 200px;" id="myTable" class="table">
<thead style="margin-right: 200px;">
<tr style="font-size: 12px;">
<th style="font-size: 12px;width: 3%;" class="lead">S.no</th>
<th style="font-size: 12px;" class="lead">Contract No.</th>
<th style="font-size: 12px;" class="lead">Commodities</th>
<th style="font-size: 12px;" class="lead">Seller</th>
<th style="font-size: 12px;" class="lead">Buyer</th>
<th style="font-size: 12px;" class="lead">FCL</th>
<th style="font-size: 12px;" class="lead">Rate</th>
<th style="font-size: 12px;" class="lead">Weight</th>
<th style="font-size: 12px;" class="lead">Bill Amount</th>
<th style="font-size: 12px;" class="lead">Commision</th>
<th style="font-size: 12px;" class="lead">Shipment Period</th>
<th style="font-size: 12px;" class="lead">ETD</th>
<th style="font-size: 12px;" class="lead">ETA</th>
<th style="font-size: 12px;" class="lead">Mode Amount</th>
<th style="font-size: 12px;display: none;" class="lead">Mode</th>
<th style="font-size: 12px;" class="lead">Status</th>
<th style="font-size: 12px;" class="lead">Action</th>
</tr>
</thead>
<tbody style="font-size: 12px;margin-right: 200px;">
<?php
$sql = "SELECT * FROM `indent`";
$result = mysqli_query($conn, $sql);
$sno = 0;
while ($row = mysqli_fetch_assoc($result)) {
$sno = $sno + 1;
echo "<tr>
<th scope='row'>" . $sno . "</th>
<td>" . $row['contractNo'] . "</td>
<td>" . $row['commodities'] . "</td>
<td>" . $row['seller'] . "</td>
<td>" . $row['buyer'] . "</td>
<td>" . $row['fcl'] . "</td>
<td>" . $row['rate'] . "</td>
<td>" . $row['weight'] . "</td>
<td>" . $row['billAmount'] . "</td>
<td id='loop' >" . $row['commision'] . "</td>
<td>" . $row['shipmentPeriod'] . "</td>
<td>" . $row['etd'] . "</td>
<td>" . $row['eta'] . "</td>
<td>" . $row['modeAmount'] . "</td>
<td style='display:none;'>" . $row['mode'] . "</td>
<td>" . $row['statusPayment'] . "</td>
<td > <button style='font-size: 12px;' data-bs-toggle='modal' data-bs-target='#editModal' class='edit btn btn-sm btn-primary' id=" . $row['sno'] . ">Edit</button> <button style='font-size: 12px;' class='delete btn btn-sm btn-primary' id=d" . $row['sno'] . ">Delete</button> </td>
</tr>";
}
?>
</tbody>
<tfoot>
<td id="total">0</td>
</tfoot>
</table>
我已经找到了如何对列求和的答案,但是在过滤它时它不会添加正在过滤的值,它只是显示所有的佣金列,汇总了该表来自 datatables.net
这是我正在运行以获取总和的函数
$(function() {
var TotalValue = 0;
$("tr #loop").each(function(index, value) {
currentRow = parseFloat($(this).text());
TotalValue += currentRow
});
document.getElementById('total').innerHTML = TotalValue;
});
它获得了所有的佣金列,但我希望在过滤后它显示总和值我希望你能理解我想要什么
【问题讨论】:
-
ID 必须在 HTML 文档中是唯一的。
-
我正在从 sql 中获取 td 值,因此使用 id 可以更轻松地告诉我过滤后如何求和\
-
使用类而不是 ID。
-
我将使用该类,但您能告诉我如何在过滤后对值求和
-
你在说什么“过滤”,我没看到。
标签: javascript php html jquery datatables