Sorting a table along column values

Example at http://hgsweb.de/tablesort

Logic

The assumption is that the sort is triggered via an onclick-event from whithin a header cell (TH). Once the event is received in the sortCore function, we work our way up the chain of parent nodes to find the the cellIndex of the TH-element and the table this TH-element belongs to. Given this, we can access all the rows in the table body and the column cell we have to sort along. The default method to access the value of the cell for comparison, is done by the function represented by the value of closure variable getValue. The default method for comparing values, is done by the fucntion represented by the value of closure variable compareValues. Both methods can be overwriten for all sort actions using the exposed functions setGrepValue, setCompareValues or individualy for every column by passing in the method as a function from outside, defined by the user. This allows the user to write her own functions depending on the content and meaning of the cell values. See example for the last column of the table, where sorting is done along the backgroudColor passing in the function getColor

Usage

JavaScript Get a pointer to sort functionality, specify the table id . var st=sortTable(id); HTML attache up/down sort functionality to elements within a TH element like this: If you want to temporarily overwrite the default function for accessing the cell value write a function like
    function getValue(tableDataCell){
        // your code here to grep value from table DataCell
        return value;
    }
Pass this function to sortCore like: If you want to temporarily overwrite the default function for comparing cell values write a function like
    function compareValue(currentCell,refrenceCell){
        // your code here to compare currentCell versus referenceCell     
        return // result of comparison as -1 or 0 or 1;
    }
Pass this function to sortCore like: Overwrite the default functionality for accessing cell values and comparison permantly say: