[tw] Re: [TWC] Help Sorting a treeview
I finally figured it out! Though it's probably the most duck tape way I could have done it. XD Since I have gotten in trouble for sharing question core mods before I won't post the copy/past details. I did core modification to add my own: sortTiddlers reverseLookup functions I named them sortTiddlersNS reverseLookupNS So that way they are only used by the treeviewplugin and shouldn't effect anything else. in the end I wound up using a slightly modfired version of this natural sorting script: https://raw.githubusercontent.com/Bill4Time/javascript-natural-sort/master/naturalSort.js After spending hours figuring out what didn't work I actually learned that as I suspected it was actually super easy to get things to work. -- 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 tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at http://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/f7059cb4-b730-4c55-8faa-8c27731c020a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[tw] Re: [TWC] Help Sorting a treeview
Looking at things store.getTaggedTiddlers() = store.reverseLookup(tags...etc) Which sorts it's output by the titles titles using sortTiddlers(). So it looks like the actual problem is somewhere in this part of the core: Which looks like a basic sort function so I just have to figure out how to turn it into a natural sort function. // Sort a list of tiddlers TiddlyWiki.prototype.sortTiddlers = function(tiddlers,field) { var asc = +1; switch(field.substr(0,1)) { case -: asc = -1; field = field.substr(1); break; case +: field = field.substr(1); break; } if(TiddlyWiki.standardFieldAccess[field]) { if(field==title) { tiddlers.sort(function(a,b) {return a[field].toLowerCase() b[field].toLowerCase() ? -asc : (a[field].toLowerCase() == b[field].toLowerCase() ? 0 : asc);}); } else { tiddlers.sort(function(a,b) {return a[field] b[field] ? -asc : (a[field] == b[field] ? 0 : asc);}); } } else { tiddlers.sort(function(a,b) {return a.fields[field] b.fields[field] ? -asc : (a.fields[field] == b.fields[field] ? 0 : +asc);}); } return tiddlers; }; On Saturday, May 30, 2015 at 7:22:54 AM UTC-7, Arc Acorn wrote: The more I tinker with this the more I think that this may require a core modification. Since it seems like the core issues is how: store.getTaggedTiddlers(); gathers it's list of tiddlers. On Wednesday, May 27, 2015 at 3:08:07 PM UTC-7, Arc Acorn wrote: This is the plugin I'm using: http://dots.tiddlyspace.com/TreeviewPluginPlugin2 As of now trees with leading numbers sort like: 1 10 100 11 12 13 2 3 4 5... I know the reason is how strings are sorted and a naturalsort function needs to be worked in: eg: function naturalSort(ar, index){ var L= ar.length, i, who, next, isi= typeof index== 'number', rx= /(\.\d+)|(\d+(\.\d+)?)|([^\d.]+)|(\.(\D+|$))/g; function nSort(aa, bb){ var a= aa[0], b= bb[0], a1, b1, i= 0, n, L= a.length; while(iL){ if(!b[i]) return 1; a1= a[i]; b1= b[i++]; if(a1!== b1){ n= a1-b1; if(!isNaN(n)) return n; return a1b1? 1: -1; } } return b[i]!= undefined? -1: 0; } for(i= 0; iL; i++){ who= ar[i]; next= isi? ar[i][index] || '': who; ar[i]= [String(next).toLowerCase().match(rx), who]; } ar.sort(nSort); for(i= 0; iL; i++){ ar[i]= ar[i][1]; } } However I can't for the life of me figure out how to incorporate the natural sort function into the treeview plugin Any help would be greatly appreciated. . -- 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 tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at http://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/c41b16f1-ca86-4a54-8e25-172c388043c6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[tw] Re: [TWC] Help Sorting a treeview
The more I tinker with this the more I think that this may require a core modification. Since it seems like the core issues is how: store.getTaggedTiddlers(); gathers it's list of tiddlers. On Wednesday, May 27, 2015 at 3:08:07 PM UTC-7, Arc Acorn wrote: This is the plugin I'm using: http://dots.tiddlyspace.com/TreeviewPluginPlugin2 As of now trees with leading numbers sort like: 1 10 100 11 12 13 2 3 4 5... I know the reason is how strings are sorted and a naturalsort function needs to be worked in: eg: function naturalSort(ar, index){ var L= ar.length, i, who, next, isi= typeof index== 'number', rx= /(\.\d+)|(\d+(\.\d+)?)|([^\d.]+)|(\.(\D+|$))/g; function nSort(aa, bb){ var a= aa[0], b= bb[0], a1, b1, i= 0, n, L= a.length; while(iL){ if(!b[i]) return 1; a1= a[i]; b1= b[i++]; if(a1!== b1){ n= a1-b1; if(!isNaN(n)) return n; return a1b1? 1: -1; } } return b[i]!= undefined? -1: 0; } for(i= 0; iL; i++){ who= ar[i]; next= isi? ar[i][index] || '': who; ar[i]= [String(next).toLowerCase().match(rx), who]; } ar.sort(nSort); for(i= 0; iL; i++){ ar[i]= ar[i][1]; } } However I can't for the life of me figure out how to incorporate the natural sort function into the treeview plugin Any help would be greatly appreciated. . -- 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 tiddlywiki+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at http://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/5086c06c-7365-43d2-862b-2673bcc59f77%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.