未捕获的TypeError:无法设置属性' _DT_CellIndex'当使用rowspan时未定义

时间:2017-11-16 12:16:23

标签: php jquery foreach html-table datatables

我有一个表,其中包含使用foreach循环填充的数据库结果的记录。 但是,表的最后一列"翻转"是具有rowspan属性的单个单元格值。 我正在使用表格的dataTable插件。

      <table class="table table-striped table-hover" id="leave_balance_table">
        <thead>
            <tr>
                <th>Leave Type</th>
                <th>Max Days</th>
                <th>Leave Taken</th>
                <th>Leave Balance</th>
                <th>Roll Over</th>
            </tr>
        </thead>
        <tbody>
        <?php
        $totalLeaveTaken = 0.00;
        $totalBalance = 0.00;
        $totalRows = count($GetEmployeeLeaveBalance);
        $lastColumnPrinted = false; //Add This
            foreach ($GetEmployeeLeaveBalance as $member):
                $totalLeaveTaken += $member['usedDays'];
                $totalBalance += $member['Remaining_Leave_Days'];
                $leaveBalance = floatval($member['Remaining_Leave_Days']);
            ?>
            <tr>
                <td><?php echo $member['title']; ?></td>
                <td><?php echo $member['maxDays']; ?></td>
                <td><?php echo $member['usedDays']; ?></td>
                <!-- <td><?php echo gettype($leaveBalance);?></td> -->
                <td
                <?= 
                ($leaveBalance < 0) ? 
                "style='background-color:red;font-weight:bold;color:white;'" : ""
                ?>
                >
                <?php echo $member['Remaining_Leave_Days']; ?>    
                </td>

                <!--Add The Line Below -->
                <?php if($lastColumnPrinted == false): $lastColumnPrinted = true;?>
                  <td rowspan="<?= $totalRows; ?>">Some computed value</td>
                <?php endif; ?>

            </tr>
        <?php endforeach; ?>
        <tr>
            <td></td>
            <td></td>
            <td style="background-color: #33CCFF; font-weight: bold;">Total: <?php echo number_format($totalLeaveTaken, 2); ?></td>
            <td style="background-color: #33CCFF; font-weight: bold;">Total: <?php echo 
            number_format($totalBalance, 2); ?></td>
            <td></td>
        </tr>
        </tbody>
    </table>

输出有点像这样:

Leave Type | Max Days | Leave Taken | Leave Balance | Roll Over
Float      | 3        | 2           | 1             | 5
Personal   | 3        | 2           | 1             |   
Sick       | 3        | 2           | 1             | 
Mourning   | 3        | 2           | 1             |

结果如预期,但我在控制台中遇到上述错误。 是因为表格中有空单元格吗?

0 个答案:

没有答案