Bug Tracker

Changeset 5794

Show
Ignore:
Timestamp:
07/25/08 08:05:17 (1 month ago)
Author:
christian.bach
Message:

Added new changes to the sort algos.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/tablesorter/2.0/jquery.tablesorter.js

    r5780 r5794  
    2222 * @desc Create a tablesorter interface and sort on the first and secound column in ascending order. 
    2323 *  
    24  * @example $('table').tablesorter({ headers: { 0: { sorter: false}, 1: {sorter: false} } }); 
     24 * @example $('table').tablesorter({ headers: { 0: { sorter: false}, 1: {sorter: false} } } }); 
    2525 * @desc Create a tablesorter interface and disableing the first and secound column headers. 
    2626 *  
     
    443443                    var order = sortList[i][1]; 
    444444                    //var s = (getCachedSortType(table.config.parsers,c) == "text") ? ((order == 0) ? "sortText" : "sortTextDesc") : ((order == 0) ? "sortNumeric" : "sortNumericDesc"); 
    445                     var s = (table.config.parsers[c].type == "text") ? ((order == 0) ? makeSortText(c) : makeSortTextDesc(c)) : ((order == 0) ? makeSortNumeric(c) : makeSortNumericDesc(c)); 
     445                    //var s = (table.config.parsers[c].type == "text") ? ((order == 0) ? makeSortText(c) : makeSortTextDesc(c)) : ((order == 0) ? makeSortNumeric(c) : makeSortNumericDesc(c)); 
     446                    var s = (table.config.parsers[c].type == "text") ? ((order == 0) ? makeSortFunction("text", "asc", c) : makeSortFunction("text", "desc", c)) : ((order == 0) ? makeSortFunction("numeric", "asc", c) : makeSortFunction("numeric", "desc", c)); 
    446447                    var e = "e" + i; 
    447448                     
     
    464465                 
    465466                if(table.config.debug) { benchmark("Evaling expression:" + dynamicExp, new Date()); } 
    466                  
     467 
    467468                eval(dynamicExp); 
    468469                 
     
    472473                 
    473474                return cache; 
     475            }; 
     476             
     477            function makeSortFunction(type, direction, index) { 
     478                var a = "a[" + index + "]", b = "b[" + index + "]"; 
     479                if (type == 'text' && direction == 'asc') { 
     480                    return "(" + a + " == " + b + " ? 0 : (" + a + " === null ? Number.POSITIVE_INFINITY : (" + b + " === null ? Number.NEGATIVE_INFINITY : (" + a + " < " + b + ") ? -1 : 1 )));"; 
     481                } else if (type == 'text' && direction == 'desc') { 
     482                    return "(" + a + " == " + b + " ? 0 : (" + a + " === null ? Number.POSITIVE_INFINITY : (" + b + " === null ? Number.NEGATIVE_INFINITY : (" + b + " < " + a + ") ? -1 : 1 )));"; 
     483                } else if (type == 'numeric' && direction == 'asc') { 
     484                    return  "(" + a + " === null && " + b + " === null) ? 0 :(" + a + " === null ? Number.POSITIVE_INFINITY : (" + b + " === null ? Number.NEGATIVE_INFINITY : " + a + " - " + b + "));"; 
     485                } else if (type == 'numeric' && direction == 'desc') { 
     486                    return  "(" + a + " === null && " + b + " === null) ? 0 :(" + a + " === null ? Number.POSITIVE_INFINITY : (" + b + " === null ? Number.NEGATIVE_INFINITY : " + b + " - " + a + "));"; 
     487                }    
    474488            }; 
    475489             
     
    756770        id: "currency", 
    757771        is: function(s) { 
    758             return /^[£$€?.]/.test(s); 
     772            return /^[£$€?.]/.test(s); 
    759773        }, 
    760774        format: function(s) {