Tablesorter always sorting descending

Tablesorter always sorting descending

When I click on a link in the table it takes me to another webpage and then when I click the back button in the browser I am taken back to the webpage with this table. Because I have the column sorting stored in the URL, the $(document).ready(function() sorts the column according to whether it used to be ascending or descending. But now the tablesorter always sorts descending when clicking on any column header.

Using Firebug, I've noticed that I get into the  recordSort() function and I specifically hit this condition ($(elem).hasClass("headerSortUp")) and it always returns true!

Any help would be appreciated.

  1. <script>
    $(document).ready(function() {
        
            var url = window.location + "";
            urlOld = url.substring(url.length - 4);
            
            if (urlOld == '#0_U') {
                $("table").tablesorter({
                      sortList: [[0,0]]
                });
            }
            else if (urlOld == '#1_U') {
                $("table").tablesorter({
                    sortList: [[1,0]]
                });
            }
            else if (urlOld == '#2_U') {
                 $("table").tablesorter({
                    sortList: [[2,0]]
                });
            }
            else if (urlOld == '#3_U') {
                $("table").tablesorter({
                    sortList: [[3,0]]
                });
            }
            else if (urlOld == '#4_U') {
                $("table").tablesorter({
                    sortList: [[4,0]]
                });
            }
            else if (urlOld == '#5_U') {
                $("table").tablesorter({
                    sortList: [[5,0]]
                });
            }
            else if (urlOld == '#6_U') {
                $("table").tablesorter({
                    sortList: [[6,0]]
                });
            }
            else if (urlOld == '#0_D') {
                $("table").tablesorter({
                      sortList: [[0,1]]
                });
            }
            else if (urlOld == '#1_D') {
                $("table").tablesorter({
                    sortList: [[1,1]]
                });
            }
            else if (urlOld == '#2_D') {
                 $("table").tablesorter({
                    sortList: [[2,1]]
                });
            }
            else if (urlOld == '#3_D') {
                $("table").tablesorter({
                    sortList: [[3,1]]
                });
            }
            else if (urlOld == '#4_D') {
                $("table").tablesorter({
                    sortList: [[4,1]]
                });
            }
            else if (urlOld == '#5_D') {
                $("table").tablesorter({
                    sortList: [[5,1]]
                });
            }
            else if (urlOld == '#6_D') {
                $("table").tablesorter({
                    sortList: [[6,1]]
                });
            }        
    });

    function recordSort(elem) {

        var url = window.location + "";
        urlOld = url.substring(url.length - 4);
        if (urlOld.charAt(0) == '#') {
            url = url.substring(0,url.length - 4);
        }    
        
        if($(elem).hasClass("headerSortUp")){        
            window.location = url + "#" + elem.cellIndex + "_" + "U";
        }
        else if($(elem).hasClass("headerSortDown")){            
            window.location = url + "#" + elem.cellIndex + "_" + "D";
        }
        //if up/down arrows and even count means it was down
        else if ((elem.count % 2) == 0){
            window.location = url + "#" + elem.cellIndex + "_" + "U";
        }






























































































  2.     //if up/down arrows and odd count means it was up
        else{
            window.location = url + "#" + elem.cellIndex + "_" + "D";
        }

    }
    </script>





  3.     <div id="resultDivCnt">
            <table id="qualReviewResult" class="tablesorter" style="width:auto;">
                <thead >
                    <tr>
                        <th style="width:auto;" onclick="recordSort(this);">Client Name</th>
                        <th style="width:auto;" onclick="recordSort(this);">Review Description</th>
                        <th style="width:auto;" onclick="recordSort(this);">Type</th>
                        <th style="width:auto;" onclick="recordSort(this);">Session<br/>Initiated</th>
                        <th style="width:auto;" onclick="recordSort(this);">Session<br/>Completed</th>
                        <th style="width:auto;" onclick="recordSort(this);">Filtered<br/>Total Credit</th>
                        <th style="width:auto;" onclick="recordSort(this);">Total Credit</th>
                    </tr>
                </thead>