JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="row">
<div class="col-md-12">
<table class="table table-bordered" style="text-align: center;" id="orders">
<thead>
<tr>
<td style="width: 2%;"></td>
<td>Prekės pavadinimas</td>
<td style="width: 15%;">Kiekis</td>
<td style="width: 15%;">Kaina</td>
<td style="width: 15%;">Suma</td>
<td style="width: 2%;"></td>
</tr>
</thead>
<tbody>
<tr>
<td style="vertical-align: middle;">
<span class="glyphicon glyphicon-menu-up"></span><br>
<span class="glyphicon glyphicon-menu-down"></span>
</td>
<td style="vertical-align: middle;">
<div class="form-group{{ $errors->has('item') ? ' has-error' : '' }}">
<label for="item"></label>
<input type="text" class="form-control" id="item" name="item" placeholder="Prekė">
</div>
</td>
<td style="vertical-align: middle;">
<div class="form-group{{ $errors->has('quantity') ? ' has-error' : '' }}">
...
JavaScript
$(document).on('keyup change', '.quantity, .price', function() {
var row = $(this).closest('tr').get(0);
var rowPrice = $(row).find('.price').val();
var rowQuantity = $(row).find('.quantity').val();
$(row).find('.total').val((rowPrice * rowQuantity).toFixed(2));
$('.total').blur(function () {
var sum = 0;
$('.total').each(function() {
sum += parseFloat($(this).val());
});
$('#totals').val((sum).toFixed(2));
});
});
$(document).on('click', '#add', function() {
$('tbody:last-child').append('<tr><td style="vertical-align: middle;"><span class="glyphicon glyphicon-menu-up"></span><br><span class="glyphicon glyphicon-menu-down"></span></td><td style="vertical-align: middle;"><div class="form-group"><label for="item"></label><input type="text" class="form-control" id="item" name="item" placeholder="Prekė"></div></td><td style="vertical-align: middle;"><div class="form-group"><label for="quantity"></label><input type="text" class="form-control quantity" name="quantity" placeholder="Kiekis"></div></td><td style="vertical-align: middle;"><div class="form-group"><label for="price"></label><input type="text" class="form-control price" name="price" placeholder="Kaina"></div></td><td style="vertical-align: middle;"><div class="form-group"><label for="total"></label><input type="text" class="form-control total" name="total" placeholder="Suma" readonly></div></td><td style="vertical-align: middle;"><a href="#"><span class="glyphicon glyphicon-remove" style="color: red;"></span></a></td></tr>');
});
$(document).on('click', '.glyphicon-remove', function() {
$(this).closest('tr').fadeOut(500, function() {
$(this).remove();
});
});
$(document).on('click', '.glyphicon-menu-up', function() {
$('tbody tr td .glyphicon-menu-up').on('click', function() {
var $row = $(this).closest('tr')
$row.insertBefore($row.prev());
});
});
$(document).on('click',...