seila

by Lucaskazama

HTML

<a href="#" id="insert-row"> Add row <i class="fas fa-plus-circle"></i></a>
<br/>
<a href="#" id="remove-row"> Remove last row <i class="fas fa-minus-circle"></i></a>
<table id="mytable" class="responsive-table">
  <caption>Statement Summary</caption>
  <thead>
    <tr>
      <th scope="col">Number</th>
      <th scope="col">Code</th>
      <th scope="col">Date</th>
      <th scope="col">Category</th>      
      <th scope="col">Type</th>
      <th scope="col">Sell</th>
      <th scope="col">Check here</th>
      <th scope="col">Payment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td data-label="Account">        
        <input type="text" name="test" value="" />
      </td>
      <td data-label="Code">
        <input type="text" name="test" value="" /></td>
      <td data-label="Date">
        <input type="date" name="test" value="" /></td>
      <td data-label="Amount">
        <select>
          <option value="volvo">Volvo</option>
          <option value="saab">Saab</option>
          <option value="opel">Opel</option>
          <option value="audi">Audi</option>
        </select>
      </td>
      <td data-label="Amount">
        <select>
          <option value="volvo">Volvo</option>
          <option value="saab">Saab</option>
          <option value="opel">Opel</option>
          <option value="audi">Audi</option>
        </select>
      </td>
      <td data-label="Amount">
        <select>
          <option value="volvo">Volvo</option>
          <option value="saab">Saab</option>
          <option value="opel">Opel</option>
          <option value="audi">Audi</option>
        </select>
      </td>
      <td data-label="Sell">
        <input type="checkbox" name="pago" id="pago" />        
      </td>
      <td data-label="Payment">
        <input type="checkbox" name="pago" id="pago" />        
      </td>
    </tr>
  </tbody>
</table>

CSS

table.responsive-table {
  border: 1px solid #ccc;
  border-collapse: collapse;
  margin: 0;
  padding: 0;
  width: 100%;
  table-layout: fixed;
}

table.responsive-table caption {
  font-size: 1.5em;
  margin: .5em 0 .75em;
}

table.responsive-table tr {
  border: 1px solid #ddd;
  padding: .35em;
}

table.responsive-table th,
table.responsive-table td {
  border: 1px solid #ddd;
  padding: .625em;
  text-align: center;
}
table.responsive-table td > *{
  box-sizing: border-box;
  width: 100%;
  display: block;
  outline:none;  
}
table.responsive-table th {
  font-size: .85em;
  letter-spacing: .1em;
  text-transform: uppercase;
}

@media screen and (max-width: 600px) {
  table.responsive-table {
    border: 0;
  }

  table.responsive-table caption {
    font-size: 1.3em;
  }
  
  table.responsive-table thead {
    border: none;
    clip: rect(0 0 0 0);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
  }
  
  table.responsive-table tr {
    border-bottom: 3px solid #ddd;
    display: block;
    margin-bottom: .625em;
  }
  table.responsive-table tr:nth-child(odd){  
    background-color:#f7f7f7;
  }
  table.responsive-table td {
    border-bottom: 1px solid #ddd;
    display: block;
    font-size: .8em;
    text-align: right;
  }
  
  table.responsive-table td::before {
    /*
    * aria-label has no advantage, it won't be read inside a table
    content: attr(aria-label);
    */
    content: attr(data-label);
    float: left;
    font-weight: bold;
    text-transform: uppercase;
  }
  
  table.responsive-table td:last-child {
    border-bottom: 0;
  }
}

JavaScript

$(document).ready(function () {
   $("#insert-row").click(function () {
      var $tableBody = $('#mytable').find("tbody"),
          $trLast = $tableBody.find("tr:last"),
          $trNew = $trLast.clone();

      $trLast.after($trNew);
  });
  $("#remove-row").click(function () {
      var $tableBody = $('#mytable').find("tbody"),
          $trLast = $tableBody.find("tr:last"),
          if($trLast.length >= 1) {
          	$trLast.remove();
          }
  });  
});