繁体   English   中英

无法设置嵌套表。 来自cakephp控制器的数据

[英]Trouble setting up a nested table. Data from cakephp controller

我正在构建一个表格,显示由...组成的行

年月总计(sum())

当您单击该行时,引导程序会展开它并显示一个嵌套表,其中包含与该月份和年份相关的更详细的数据行。

我相信我的数据来自控制器。 我需要进行查询以获得年,月和总和()每月的总数。

然后我做一个find()来获取子行。

它们都被传递给totalResiduals数组。

我的html / view看起来像这样

<div id="residuals" class="tab-pane">
            <table class="table table-striped-yellow table-bordered table-condensed">
                <thead>
                    <th>Year</th>
                    <th>Month</th>
                    <th>Total</th>
                </thead>
                <?php foreach($totalResiduals as $year => $monthResiduals): ?>
                    <?php foreach($monthResiduals as $month => $residuals): ?>
                    <tr data-toggle="collapse" data-parent="#accordion" href="#<?php echo $month; ?>" aria-expanded="false" style="cursor:pointer;">
                        <td><?php echo $year; ?></td>
                        <td><?php echo $month; ?></td>
                        <td><?php echo $residuals['paidTotal'];?></td>
                    </tr>
                    <tr id="<?php echo $month; ?>" class="collapse">
                        <td>
                            <table>
                                <thead>
                                    <th>Product Type</th>
                                    <th>Product Group</th>
                                    <th>Volume</th>
                                    <th>Paid</th>
                                </thead>
                                <?php foreach($residuals['residuals']  as $residual); ?>
                                    <tr>
                                        <td><?php echo $residual['product_type'] ?></td>
                                        <td><?php echo $residual['product_group'] ?></td>
                                        <td><?php echo $residual['volume'] ?></td>
                                        <td><?php echo $residual['paid'] ?></td>
                                    </tr>
                                <?php endforeach; ?>
                            </table>
                        </td>
                    </tr>
                    <?php endforeach; ?>

            </table>

最终发生的事情是,行最终会以折叠的嵌套行结束。 最初将显示1行,单击它,打开1个子/嵌套行。 单击它,打开1个主行,但在该子行中嵌套/折叠。

我想要发生的事情看起来像这样:

Year Month Total
2015 4     $30
   Type    Group   Volume Paid
   Product Product $0.00  $10.00
   Product Product $0.00  $10.00
   Product Product $0.00  $10.00

2015 5     $50
   Type    Group   Volume Paid
   Product Product $0.00  $25.00
   Product Product $0.00  $25.00

我假设我的错误在我看来,所以请让我知道我可以提供的其他信息,我已经遗漏了。

这是我的数据的print_r

Array

[2015] => Array
    (
        [1] => Array
            (
                [paidTotal] => 11.47
                [residuals] => Array
                    (
                        [0] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 11.47
                            )

                    )

            )

        [2] => Array
            (
                [paidTotal] => 5.77
                [residuals] => Array
                    (
                        [0] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 5.77
                            )

                    )

            )

        [4] => Array
            (
                [paidTotal] => 30.47
                [residuals] => Array
                    (
                        [0] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 12.06
                            )

                        [1] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 5.83
                            )

                        [2] => Array
                            (
                                [product_type] => HRV Residuals
                                [product_group] => HRV Residuals
                                [volume] => 0.00
                                [paid] => 12.58
                            )

                    )

            )

提前致谢,

史蒂芬

乍一看,不应该这块

<tr data-toggle="collapse" data-parent="#accordion" href="#<?php echo $month; ?>" aria-expanded="false" style="cursor:pointer;">
                        <td><?php echo $year; ?></td>
                        <td><?php echo $month; ?></td>
                        <td><?php echo $residuals['paidTotal'];?></td>
                    </tr>

,在这之外

<?php foreach($monthResiduals as $month => $residuals): ?>

, 像是

<?php foreach($totalResiduals as $year => $monthResiduals): ?>
<tr data-toggle="collapse" data-parent="#accordion" href="#<?php echo $month; ?>" aria-expanded="false" style="cursor:pointer;">
                        <td><?php echo $year; ?></td>
                        <td><?php echo $month; ?></td>
                        <td><?php echo $residuals['paidTotal'];?></td>
                    </tr>
                    <?php foreach($monthResiduals as $month => $residuals): ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM