tablesortingplugin - autosort problem

14 views
Skip to first unread message

M)

unread,
Mar 14, 2009, 11:36:41 PM3/14/09
to TiddlyWiki
Has anyone else found that the autosort doesn't work in the first
column?

|sortable|k
|<<autosort>>1|2|h
|b|b|
|a|a|

FND

unread,
Mar 15, 2009, 8:54:38 AM3/15/09
to Tiddl...@googlegroups.com
> Has anyone else found that the autosort doesn't work in the first
> column?

A sample document would really make it easier for us to analyze this...


-- F.


* cf. http://www.tiddlywiki.org/wiki/Troubleshooting

cmari

unread,
Mar 15, 2009, 10:12:07 AM3/15/09
to TiddlyWiki
I don't think this one needs a sample document. In an an empty TW
containing only the TableSortingPlugin and a tiddler containing the
above contents, the first column of the table does not automatically
sort. But I can't contribute anything more constructive than that....
cmari

FND

unread,
Mar 15, 2009, 10:16:18 AM3/15/09
to Tiddl...@googlegroups.com
> I don't think this one needs a sample document.

The reason I asked for a sample document is that, frankly, I don't wanna
have to do that myself.
I'm happy to assist with analyzing problems, but if it takes effort to
get to the problem in the first place, that's a significant barrier.


-- F.

M)

unread,
Mar 16, 2009, 10:39:18 AM3/16/09
to TiddlyWiki
Have a look here:

http://example1m.tiddlyspot.com/

M)

On Mar 15, 9:16 am, FND <F...@gmx.net> wrote:

Eric Shulman

unread,
Mar 16, 2009, 11:37:21 AM3/16/09
to TiddlyWiki, lew...@gmail.com
> http://example1m.tiddlyspot.com/

I think it's actually a logic error in TableSortingPlugin!!

The following bits of plugin code (in the hijacked version of
refreshTiddler()), are used to locate the desired 'autosort' column...
what is *supposed* to do is set the value of 'x' to the index of the
'autosort' column and then, after looping over all the
'headers' (i.e., the table columns), *if* an autosort column was
found, sorts the table by that column.
-----------------------------
var x = null
...
for (var j=0; j<headers.length; j++){
...
if(!x && hasClass(h,"autosort")) {
x = j;
...
}
}
...
if(x)
c.sortTable(headers[x],rev);
-----------------------------

The problem occurs because the table column index (j) is *zero*
based. That is, the first column of the table has an index of j==0,
the second column has j==1, etc. However, when the "if(x)" is
evaluated, 'null' and '0' are both considered be 'false'. Thus,
autosorting will only occur if the index is > 0 (i.e., any other
column *except* the first one... which is exactly the symptom you
observed.)

The fix is to use a more precise conditional by changing these two
lines:
if(!x && hasClass(h,"autosort")) {
if(x)
to:
if(x===null && hasClass(h,"autosort")) {
if(x!==null)

That should do it.

Note: I've cc'ed Saq (the plugin author) on this, as I'm sure he'll
want to update the official code...

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

M)

unread,
Mar 16, 2009, 1:07:12 PM3/16/09
to TiddlyWiki
Fantastic. Thanks!

M)

unread,
Mar 17, 2009, 9:50:27 AM3/17/09
to TiddlyWiki
Here's something interesting. After the tiddler is edited, it gets
reverse sorted. Is there a fix for that?

Check it out... http://example1m.tiddlyspot.com/

M)

On Mar 16, 1:07 pm, "M)" <marc.bu...@gmail.com> wrote:
> Fantastic.  Thanks!
Reply all
Reply to author
Forward
0 new messages