This is the scenario:
- One table with 5 rows.
- Row 1 - displays total purchase.
- Row 2 - displays total Fruits purchase.
- Row 3 - displays total Vegetables purchase.
- Row 4 - Is a fruits table with n fruits, generated dynamically with php.
- Row 5 - Is a vegetable table with n vegetable, generated dynamically with php.
As you can see in the fiddle link, the user must choose the quantity of a specific product, so the final price for this product is updated and the total and group price as well.
I could do this using jquery, but I would like to accomplish this task using AngularJs.
I've started to code. But so far I have one issue. It dipslays $NaN in the total product line.
- So, how to avoid display this
$NaNwhen there is nothing inside quantity? - How to link the 3 totals fields to each individual products group?
Note. The approach I have used is not the best one. Feel free to change the approach.
Any suggestion? JSFIDDLE
<table style='width:100% ;border: 2px solid #00BABF;' ng-app=''>
<tr>
<td>Total: $<span id='total'></span></td>
</tr>
<tr>
<td>Fruit: $<span id='tot_fruit'></span></td>
</tr>
<tr>
<td>Veget: $<span id='tot_veget'></span></td>
</tr>
<tr id='fruits'>
<td>
<table id='tbl_fruits' style='width:100% ;border: 2px solid red;'>
<tr>
<th style=' padding: 10px; text-align: left;'>Name</th>
<th style=' padding: 10px; text-align: left;'>Quanty</th>
<th style=' padding: 10px; text-align: left;'>Price</th>
<th style=' padding: 10px; text-align: left;'>Total</th>
</tr>
<tr id='Fruit_1ID'>
<td class="name">Fruit_1</td>
<td><input id='qty_Fruit_1ID' ng-model='Fruit_1ID'></td>
<td>$<span id='price_Fruit_1ID'>10</span></td>
<td>$<span id='tot_Fruit_1ID'>{{Fruit_1ID*10}}</span></td>
</tr>
<tr id='Fruit_nID'>
<td class="name">Fruit_n</td>
<td><input id='qty_Fruit_nID' ng-model='Fruit_nID'></td>
<td>$<span id='price_Fruit_nID'>5</span></td>
<td>$<span id='tot_Fruit_nID'>{{Fruit_nID*5}}</span></td>
</tr>
</table>
</td>
</tr>
<tr id='vegetable'>
<td>
<table id='tbl_vegetabl' style='width:100% ;border: 2px solid green;'>
<tr>
<th style=' padding: 10px; text-align: left;'>Name</th>
<th style=' padding: 10px; text-align: left;'>Quanty</th>
<th style=' padding: 10px; text-align: left;'>Price</th>
<th style=' padding: 10px; text-align: left;'>Total</th>
</tr>
<tr id='Vegetab_1ID'>
<td class="name">Vegetab_1</td>
<td><input id='qty_Vegetab_1ID' ng-model='Vegetab_1ID'></td>
<td>$<span id='price_Vegetab_1ID'>7</span></td>
<td>$<span id='tot_Vegetab_1ID'>{{Vegetab_1ID*7}}</span></td>
</tr>
<tr id='Vegetab_nID'>
<td class="name">Vegetab_n</td>
<td><input id='qty_Vegetab_nID' ng-model='Vegetab_nID'></td>
<td>$<span id='price_Vegetab_nID'>3</span></td>
<td>$<span id='tot_Vegetab_nID'>{{Vegetab_nID*3}}</span></td>
</tr>
</table>
</td>
</tr>
</table>