JSFiddle - React, Tailwind, and code Playground
HTML
Name: <input type="text" name="name" id="name"><br>
Status: <input type="text" name="status" id="status">><br>
<button>Click</button><br><br>
<table id="myTable">
<thead>
<tr>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Doe, John</td>
<td>Approved</td>
</tr>
<tr>
<td>aaa, John</td>
<td>Approved</td>
</tr>
</tbody>
</table>
JavaScript
function myFunction(name, status) {
var table = document.getElementById('myTable').getElementsByTagName('tbody')[0];
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = name;
cell2.innerHTML = status;
var tbody = $('#myTable').find('tbody');
var newRows = tbody.find('tr').sort(function (a, b) {
return $('td:first', a).text().localeCompare($('td:first', b).text());
});
console.log(newRows);
tbody.append(newRows);
}
$('button').click(function() {
myFunction(
document.getElementsByName('name')[0].value,
document.getElementsByName('status')[0].value);
});
myFunction('Jones, Bob', 'Approved');