JSFiddle - React, Tailwind, and code Playground

by Sergey Shaliapin

HTML

<table id="myTable" cellspacing="0">
	<thead>
    <tr>
      <th>ID</th>
      <th>Title</th>
      <th>Quantity</th>
      <th>Price</th>
      <th>Summ</th>
      <th>Discount, %</th>
      <th>Total</th>
    </tr>
	</thead>
	<tbody>
	  <tr>
      <td>1</td>
      <td>Bread</td>
      <td>1</td>
      <td>10</td>
      <td>10</td>
      <td>1</td>
      <td>9.9</td>
    </tr>
    <tr>
      <td>2</td>
      <td>Butter</td>
      <td>2</td>
      <td>7</td>
      <td>14</td>
      <td>2</td>
      <td>13.72</td>
    </tr>
	</tbody>
	<tfoot>
	  <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td>23.62</td>
    </tr>
	</tfoot>
</table>
<div class="container">
  <button>Add</button>
  <button>Delete</button>
</div>

CSS

body {
  font: 16px Arial;
  background-color: #d9d9d9;
}
table {
  margin: 20px auto;
  border-radius: 4px;
  box-shadow: 0 0 10px rgba(0,0,0,0.2), 0 2px 3px rgba(0,0,0,0.4);
}
td, th {
  padding: 10px;
}
th:first-child {
  border-top-left-radius: 4px;
}
th:last-child {
  border-top-right-radius: 4px;
}
tfoot td:first-child {
  border-bottom-left-radius: 4px;
}
tfoot td:last-child {
  border-bottom-right-radius: 4px;
}
td {
  text-align: center;
}
th {
  text-transform: uppercase;
}
thead tr {
  background-color: #fb6362;
  color: #ffffff;
}
tfoot tr {
  background-color: #404a58;
  color: #ffffff;
}
tbody tr {
  background-color: #ffffff;
  color: #999999;
}
tbody tr:nth-child(even) {
  background-color: #f4f4f4;
}
.container {
  margin: 0 auto;
  width: 264px;
}
.container button {
  width: 128px;
  height: 48px;
  float: left;
  text-transform: uppercase;
  border: none;
  background-color: #fb6362;
  color: #ffffff;
  margin: 2px;
  display: block;
  box-shadow: 0 3px 5px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.8);
  border-radius: 4px;
  font-size: 15px;
  font-family: sans-serif;
  cursor: pointer;
  -webkit-transition: background-color 0.2s; 
  -moz-transition: background-color 0.2s; 
  -ms-transition: background-color 0.2s; 
  -o-transition: background-color 0.2s; 
  transition: background-color 0.2s; 
}
.container button:hover {
  background-color: #f98584;
}
.container button:active {
  background-color: #f98584;
  position: relative;
  top: 2px;
}

JavaScript

// © EPAM JS lab 2016
// DOM, BOM, events.

// Task:
// Add button must add new row below with user selected data (Title, Quantity, Price, Discount).
// "Summ" and "Total" fields must get counted values.
// Delete button must remove last row.
// "In total" field (sum of total values) must be recounted on any action.
// Maximum number of digits after the decimal point is 2 in any value.

// * Additional task:
// When click on the field (Quantity, Price, Discount) it must become editable. Blur will apply new value and make "Total" field recounted.
// When click on the field (ID, Title, Summ, Total) row must be highlighted. If then click Delete button it will remove highlighted row.