After receiving an array of objects in the form of a JSON file and using AJAX to display specific key-value pairs in a table, I am now faced with the task of sorting the rendered table. However, I am uncertain about the steps to take next.
<div id="data-table">
<table id="html-data-table">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</table>
</div>
The JavaScript code responsible for generating the table is as follows:
newData.map(row => {
let newRow = document.createElement("tr"); // new row is created
Object.values(row).map((value) => {
let cell = document.createElement("td"); // new data for the row is added
cell.innerText = value;
newRow.appendChild(cell);
})
mytable.appendChild(newRow);
});
I am interested in sorting both columns individually. Can anyone suggest a method that can be used for this purpose?