const productoList = document.querySelector('#productoList');
var countList = 1;
const addProduct = () => {
let props = {
id: `product_${countList}`,
classList: 'div-transition div-hide',
hidden: 'hidden'
}
let html = transformHTML(`
<tr>
<td>Producto ${countList}</td>
<td>${countList}${countList}${countList}</td>
<td>
<button class="btn btn-danger" onclick="deleteRow('${props.id}')">
<i class="fa-solid fa-trash-can"></i>
</button>
</td>
</tr>
`);
productoList.addRow(html, 'last', props);
document.querySelector(`#${props.id}`).elementTransition('show');
countList++;
}
const addManyProduct = () => {
let props = {
id: `product_${countList}`,
classList: 'div-transition div-hide',
hidden: 'hidden'
}
let html = transformHTML(`
<tr>
<td>Producto ${countList}</td>
<td>${countList}${countList}${countList}</td>
<td>
<button class="btn btn-danger" onclick="deleteRow('${props.id}')">
<i class="fa-solid fa-trash-can"></i>
</button>
</td>
</tr>
`);
countList++;
let props2 = {
id: `product_${countList}`,
classList: 'div-transition div-hide',
hidden: 'hidden'
}
let html2 = transformHTML(`
<tr>
<td>Producto ${countList}</td>
<td>${countList}${countList}${countList}</td>
<td>
<button class="btn btn-danger" onclick="deleteRow('${props2.id}')">
<i class="fa-solid fa-trash-can"></i>
</button>
</td>
</tr>
`);
productoList.addRow(html, 'last', props);
productoList.addRow(html2, 'last', props2);
let el1 = document.querySelector(`#${props.id}`);
let el2 = document.querySelector(`#${props2.id}`);
[el1, el2].elementTransition('show');
countList++;
}
const clearProducts = () => {
document.querySelector('#productoList tbody').innerHTML = '';
countList = 1;
}
const deleteRow = async(id) => {
let el = document.querySelector(`#${id}`);
el.elementTransition('hide');
setTimeout(() => {
el.deleteRow();
}, 400);
}
<div class="col-md-12">
<button class="btn btn-primary" onclick="addProduct()">
<i class="fa-solid fa-circle-plus"></i> Add product
</button>
<button class="btn btn-primary ms-2" onclick="addManyProduct()">
<i class="fa-solid fa-circle-plus"></i> Add many product
</button>
<button class="btn btn-outline-secondary float-end" onclick="clearProducts()">
<i class="fa-solid fa-arrows-rotate"></i>
</button>
</div>
<div class="col-md-12 mt-2">
<table id="productoList" class="table table-bordered">
<thead>
<tr>
<th>Product Name</th>
<th>Code</th>
<th>Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>