[英]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.