In my drop down menu If I Choose Timestamp, It should sort the TimeStamp in ascending/descending order or If I choose Host it should sort Host in ascending/descending order.
Currently I'm using Tablesorter plugin and it doesn't seem to work.
var value = $('#sourceDropdown :selected').text();
if(value == "TimeStamp"){
$("#myTable").tablesorter({
headers: {
0: {
sorter: true
}
}
});
console.log("sorted"+ value);
}
else if(value=="Host") {
$("#myTable").tablesorter({
headers: {
1: {
sorter: true
}
}
});
console.log("sorted" +value);
}
else{
console.log(value+" is not a valid option");
}
Looks like instead of telling it to sort, you are specifying which columns to allow sorting on. In order to sort the column you would use:
var sorting = [[0,0]];
// sort on the first column
$("table").trigger("sorton",[sorting]);
So in your case this should work:
var value = $('#sourceDropdown :selected').text();
if(value == "TimeStamp"){
var sorting = [[0,0]];
$("table").trigger("sorton",[sorting]);
console.log("sorted"+ value);
}
else if(value=="Host") {
var sorting = [[1,0]];
$("table").trigger("sorton",[sorting]);
console.log("sorted" +value);
}
else
{
console.log(value+" is not a valid option");
}