I have a requirement to sort a table when click on title link. When click the link first time table should sort ascending order when click on next time table should sort in descending order. I have written PHP back end code it was working fine. But i don't know how to pass the required parameter when click on link using Javascript.
My table html
<table class="table table-bordered table-striped">
<thead>
<tr>
<th><b>#</b></th>
<th><b id = "name_sort">Email</b> </th>
<th ><b >Name</b></th>
<th><b>Team</b> </th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Javascript
$(function() {
$('#name_sort').click(function() {
window.location.href = "http://testdomain.com/admin-home?sort=email&sort_type=asc";
// when click again i need change the url to descending
http://testdomain.com/admin-home?sort=email&sort_type=desc
});
});
I dont know how to implement it in Front end using JS. Please help me to solve this issue.