JSFiddle - React, Tailwind, and code Playground
by Андрей Хамедов
HTML
<table class="table-data">
<tr class="table-data__row">
<th class="table-data__cell table-data__cell_h">
<label class="table-data__label">
<input class="table-data__input" type=checkbox name="common">
</label>
</th>
<th class="table-data__cell table-data__cell_h">
<span class="table-data__cell-inner">
<span class="table-data__cell-icon"><i class="fa fa-sort fa-sort-amount-asc"></i></span>
<span class="table-data__cell-text">Date</span>
</span>
</th>
<th class="table-data__cell table-data__cell_h">
<span class="table-data__cell-inner">
<span class="table-data__cell-icon"><i class="fa fa-sort"></i></span>
<span class="table-data__cell-text">Order type</span>
</span>
</th>
<th class="table-data__cell table-data__cell_h">
<span class="table-data__cell-inner">
<span class="table-data__cell-icon"><i class="fa fa-sort fa-sort-amount-desc"></i></span>
<span class="table-data__cell-text">Address</span>
</span>
</th>
<th class="table-data__cell table-data__cell_h">
<span class="table-data__cell-inner">
<span class="table-data__cell-icon"><i class="fa fa-sort"></i></span>
<span class="table-data__cell-text">Comment</span>
</span>
</th>
<th class="table-data__cell table-data__cell_h">
<span class="table-data__cell-inner">
<span class="table-data__cell-icon"><i class="fa fa-sort"></i></span>
<span class="table-data__cell-text">Quantity</span>
</span>
</th>
<th class="table-data__cell table-data__cell_h">
<span class="table-data__cell-inner">
<span class="table-data__cell-icon"><i class="fa fa-sort"></i></span>
<span class="table-data__cell-text">Product</span>
</span>
</th>
<th class="table-data__cell table-data__cell_h">
<span class="table-data__cell-inner">
<span class="table-data__cell-icon"><i class="fa...
CSS
.table-data {
margin: 0 auto;
border-collapse: collapse;
}
.table-data__cell {
padding: 5px;
border: 1px solid gray;
}
.table-data__cell-inner {
display: inline-block;
width: 130px;
font-size: 0;
text-align: center;
}
.table-data__cell-icon {
box-sizing: border-box;
display: inline-block;
vertical-align: middle;
width: 13%;
font-size: 16px;
}
.table-data__cell-text {
box-sizing: border-box;
display: inline-block;
vertical-align: middle;
width: 87%;
padding-left: 8px;
font-size: 16px;
text-align: left;
}
.table-data__cell_h:hover {
background-color: lightgrey;
cursor: pointer;
transition: background-color 0.5s;
}
.table-data__cell_h:hover:first-child {
background-color: transparent;
}
.table-data__cell_field {
padding: 5px;
background: #f5f5f5;
}
.table-data__search {
box-sizing: border-box;
width: 100%;
padding: 4px 5px;
border: 1px solid #ccc;
background: white;
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2);
}
.table-data__select {
box-sizing: border-box;
width: 100%;
padding: 4px;
border: 1px solid #ccc;
outline: none;
cursor: pointer;
}
.table-data__search:focus,
.table-data__select:focus {
box-shadow: 0 0 5px rgba(50, 200, 255, 0.5);
outline: none;
}
.table-data__cell:first-child {
padding: 0;
text-align: center;
}
.table-data__label {
box-sizing: border-box;
display: block;
height: 100%;
padding: 10px 20px;
}
JavaScript
var ordersSelectors = document.querySelectorAll('td .table-data__input');
var commonSelector = document.querySelector('th .table-data__input');
var checkedCount = 0
for (var i = 0; i < ordersSelectors.length; i++) {
ordersSelectors[i].onclick = function(event) {
// var checkedCount = document.querySelectorAll('td .table-data__input:checked').length;
event.target.checked ? ++checkedCount : --checkedCount;
commonSelector.checked = checkedCount > 0;
commonSelector.indeterminate = checkedCount > 0 && checkedCount < ordersSelectors.length;
}
}