我有一个允许用户搜索的表,它将根据结果自动计算总数。我正在隐藏不符合搜索条件的行。
Here's my table actual data
当我开始搜寻
this is what i got
请注意,总数不正确,但是 当我添加另一个按键here's the result
这是我的jquery代码,用于基于搜索计算所有可见行。
$(document).ready(function() {
$("#getSearch").keydown(function(event) {
var rows = $('#table2 tbody tr:visible').length;
if (rows < 1) {
oNrecalculate();
} else {
var regAreaIs = 0;
$('#table2 tbody tr:visible').each(function(index) {
if ($('#reference_col0').css('display') != 'none') {
$(this).find(".TotalRegAreaFoot").each(function() {
var reg = $(this).text();
regAreaIs += parseFloat(reg);
}); // end loop
} else {
$(this).find(".TotalRegAreaFoot").each(function() {
var reg = $(this).text();
regAreaIs += parseFloat(reg);
}); // end loop
}
});
$('#TOTALregAREA').text(regAreaIs); // displaying total on footer
}
});
});
我无法粘贴我的整个html代码,但是结构看起来像这样。
<input name="keyword" id="getSearch" class="search selectable" type="text" placeholder="Search" data-column="all">
<table id="table2" class="SeedlingTblRep">
<thead>
<tr>
<th>Reg Area</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mssql_fetch_array($data))
{
$TotalRegArea += $row["RegArea"];
?>
<tr id="reference_col0">
<td class="TotalRegareaFoot" align="right">
<?php echo number_format($row["RegArea"], 2);?>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot id="tpaa">
<tr>
<th id="totalDisplay"><a href="#" id="btnRefresh"
onclick="oNrecalculate()"><i class="fas fa-sync-alt"></i> </a>Total:</th>
<th id="TOTALregAREA" align="right">
<?php echo number_format($TotalRegArea, 2);?>
</th>
</tr>
</tfoot>
</table>
我认为问题在于循环所有可见的第一个初始化的表行是键按下并且计算尚未初始化。
有没有办法解决这个问题? 先感谢您, 对不起,语法不好。