I have three table headers, each with ID’s: deadline_column, duration_column, and description_column
Each <th> has an class of ‘headerSort’. What I’m trying to do right now is, once one of the headings are clicked: determine the column clicked, and then alternate between ascending and descending. The main trouble I’m having is going back to the default sort (ascending) when a new column is clicked. Right now I have:
$(document).ready(function(){
var order;
var column;
$('.headerSort').on('click', function(){
var column = $(this).attr('id');
if (order=='ascending'){
order = 'descending';
} else {
order = 'ascending';
}
alert (order);
// deadline_column
// duration_column
// description_column
// switch(column){
// case 'deadline_column':
// break;
// case 'duration_column':
// break;
// case 'description_column':
// break;
// }
});
I can’t think up a way to do this that won’t come out being overly verbose.
What about something like this?