1
I have a dynamically created order table, the user selects the item, the quantity, and whether it is for loan or not, and adds the item in the table.
I needed that when adding again an item that is already inserted in the table (for example the mouse, whose ID is 8) and that the loan column also have the same value, instead of adding a new row to the mouse, increase the amount of the existing row in the table, and I don’t know how to do.
So I need, when adding a new product, to check all the rows in the table in the ID column if there is already the ID of this product being inserted and if the LOAN column of this row also has the same value as the one being inserted, if the 2 conditions are true, instead of adding a new line, just increase the amount of the existing line.
<table id="tabela_pedido">
<thead>
<tr>
<th>Item</th>
<th>Quantidade</th>
<th>Empréstimo</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<td style="display:none;">8</td>
<td>Mouse</td>
<td>2</td>
<td>Sim</td>
<td><button class="btn btn-large btn-danger" onclick="RemoveTableRow(this)" type="button">Remover</button></td>
</tbody>
</table>
Where: the first column that is hidden is the item ID, the second the name, the third the amount being ordered, the third whether it is a loan item or not, and the fourth an action to remove the line
What kind of data are you working on? I mean, product data
– Johnny Gabriel
is a product that has ID, name, quantity in stock. and in the order is inserted the product ID and the requested quantity
– Marcelo
OK, but how do you control the selected products? With array? Or just add in table?
– Johnny Gabriel
I just added it to the table
– Marcelo
You could try using Datatables for this, and you can still increment your table with search, sort, etc. https://datatables.net/manual/data/
– dap.tci