Hi Stephan,

then you force me to look at the code without having explored yet all the 
things described in TW5 beta?

Oh, well... sooner or later I would have done :D

Anyway, sorry, but I can't test the code right now, maybe tomorrow, but at 
first glance it seems correct to me.
Mh... maybe no... You do a numeric comparison only when both values are 
numeric, otherwise you compare two strings. It's OK if you have lists with 
only numbers or only strings, but using it on a list with numbers and 
strings, you use the numeric mode everytime you have two "numeric strings", 
probably resulting in a list ordered numerically where you have numeric 
values and alphabetically where you have strings.
I think the only way to do this is to add the parameter "isNumeric" to the 
function.

Something like this (don't know the original code right now):

exports.sortTiddlers = function(titles,sortField,isDescending,
isCaseSensitive,isNumeric) {
    var self = this;
    titles.sort(function(a,b) {
        if(sortField !== "title") {
            a = self.getTiddler(a).fields[sortField] || "";
            b = self.getTiddler(b).fields[sortField] || "";
        }
        
        if (isNumeric) {
            a = a-0;
            b = b-0;
        } else if(!isCaseSensitive) {
            if(typeof a === "string") {
                a = a.toLowerCase();
            }
            if(typeof b === "string") {
                b = b.toLowerCase();
            }
        }

        if(a < b) {
            return isDescending ? +1 : -1;
        } else {
            if(a > b) {
                return isDescending ? -1 : +1;
            } else {
                return 0;
            }
        }
    });
};




OK, thank you for pointing me in the right direction! I'll start from here. 
Anyway, in general, I prefer not to change the core code so I can upgrade 
TW on every new release, everywhere and without to recompile (only with a 
drag & drop of the html file).

This means that I have to learn the new plugin system and the new 
architecture >_<


-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywiki.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to