I''ve put together a little library to provide sortable tables. It is heavily copied from http://www.kryogenix.org/code/browser/sorttable/ (mentioned in the Wish List) but has been modified to match the same form as the prototype.js library and add some new features. I still need to clean up some of the comments, but everything is pretty much working at this point. I posted an example at http://tom-mack.com/tablesort/. I''d be happy to make any changes necessary to make this code more compatible with the rest of the scriptaculous stuff, but I need some advice on how to proceed. (I''m a little new to Javascript, especially this OO style, so any suggested improvements along those lines would be appreciated.) --Tom
I don''t know if it is a bug or not (I assume it is or I would not be writing) but when you click on the 1,000 column it takes two click to make it sort and the sort direction does not follow the arrow. I tried on multiple PC''s and multiple browsers. On 8/12/05, Tom Mack <rails-spinoffs@tom-mack.com> wrote:> > I''ve put together a little library to provide sortable tables. It is > heavily copied from http://www.kryogenix.org/code/browser/sorttable/ > (mentioned in the Wish List) but has been modified to match the same > form as the prototype.js library and add some new features. I still need > to clean up some of the comments, but everything is pretty much working > at this point. > > I posted an example at http://tom-mack.com/tablesort/. I''d be happy to > make any changes necessary to make this code more compatible with the > rest of the scriptaculous stuff, but I need some advice on how to > proceed. (I''m a little new to Javascript, especially this OO style, so > any suggested improvements along those lines would be appreciated.) > > --Tom > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20050812/095598d0/attachment.html
I should also mention that it is very cool. On 8/12/05, Ira Burton <ira.burton@gmail.com> wrote:> > I don''t know if it is a bug or not (I assume it is or I would not be > writing) but when you click on the 1,000 column it takes two click to make > it sort and the sort direction does not follow the arrow. I tried on > multiple PC''s and multiple browsers. > > On 8/12/05, Tom Mack <rails-spinoffs@tom-mack.com> wrote: > > > > I''ve put together a little library to provide sortable tables. It is > > heavily copied from http://www.kryogenix.org/code/browser/sorttable/ > > (mentioned in the Wish List) but has been modified to match the same > > form as the prototype.js library and add some new features. I still need > > > > to clean up some of the comments, but everything is pretty much working > > at this point. > > > > I posted an example at http://tom-mack.com/tablesort/. I''d be happy to > > make any changes necessary to make this code more compatible with the > > rest of the scriptaculous stuff, but I need some advice on how to > > proceed. (I''m a little new to Javascript, especially this OO style, so > > any suggested improvements along those lines would be appreciated.) > > > > --Tom > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20050812/c9087bc3/attachment.html
Wow good catch. It is actually an artifact of the method used to determine what sorting function (e.g. numeric, currency, text) to use. Only the first row is checked to determine the type for the whole column. When "n/a" is in the first row, it sorts the whole column alphabetically. When "0.0160" is in the first row it sorts the whole column numerically. I think the solution is to make a smarter sorting function that can compare number to number, string to number, number to string, and string to string. Shouldn''t be too hard, but its Friday evening, so it''s going to have to wait! --Tom Ira Burton wrote:> I don''t know if it is a bug or not (I assume it is or I would not be > writing) but when you click on the 1,000 column it takes two click to > make it sort and the sort direction does not follow the arrow. I tried > on multiple PC''s and multiple browsers.
> I''ve put together a little library to provide sortable tables. It is > heavily copied from http://www.kryogenix.org/code/browser/sorttable/ > (mentioned in the Wish List) but has been modified to match the same > form as the prototype.js libraryThis doesn''t seem to work at all on Safari. I''m unable to check the kryogenix version right now, his site''s not responding.
I''ve uploaded a new version that handles mixed data types in a column (the bug the Ira noticed). http://www.tom-mack.com/tablesort/ Also, I''ve investigated the Safari issue. It is mostly working (it sorts the table initially when the page loads) and I get the click event when a column is clicked. But, I think there might be a bug in Event.element(event) from the prototype.js code because I''m not getting back the source element of the event (or I''m just using it wrong). Anyone have any ideas on that? --Tom
Anybody know of any js table sorting solution that works in other languages such as chinese, japanese, english, or french combined or seperate? The only way I have found to do it is to use ajax to search and sort using the db and bring back all the results to populate the table again. On 8/14/05, Tom Mack <rails-spinoffs@tom-mack.com> wrote:> > I''ve uploaded a new version that handles mixed data types in a column > (the bug the Ira noticed). > > http://www.tom-mack.com/tablesort/ > > Also, I''ve investigated the Safari issue. It is mostly working (it > sorts the table initially when the page loads) and I get the click > event when a column is clicked. But, I think there might be a bug in > Event.element(event) from the prototype.js code because I''m not getting > back the source element of the event (or I''m just using it wrong). > > Anyone have any ideas on that? > > --Tom > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Eric Fleming efleming@gmail.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails-spinoffs/attachments/20050814/5dd6d421/attachment-0001.html
I have a suggested change. Before line 86: this.sortColumnIndex = column; add something like the following: for ( i=0; i<table.rows[1].cells.length; i++ ) { if ( table.rows[1].cells[i].cellIndex == td.cellIndex ) { column = i; } } This may seem redundant, but it''s necessary in the application I''m using it for. In my app, I allow columns to be hidden via js. At least in IE/Win, the value of cellIndex for any columns to the right of a hidden column no longer matches the index of the cells array, making the for loop necessary. Setting column = td.cellIndex doesn''t work under those circumstances. Make sense? Dave Strus ________________________________________ From: rails-spinoffs-bounces@lists.rubyonrails.org [mailto:rails-spinoffs-bounces@lists.rubyonrails.org] On Behalf Of Eric Fleming Sent: Sunday, August 14, 2005 8:09 PM To: rails-spinoffs@lists.rubyonrails.org Subject: Re: [Rails-spinoffs] Sortable Tables Anybody know of any js table sorting solution that works in other languages such as chinese, japanese, english, or french combined or seperate?? The only way I have found to do it is to use ajax to search and sort using the db and bring back all the results to populate the table again. On 8/14/05, Tom Mack <rails-spinoffs@tom-mack.com> wrote: I''ve uploaded a new version that handles mixed data types in a column (the bug the Ira noticed). http://www.tom-mack.com/tablesort/ Also, I''ve investigated the Safari issue. It is mostly working (it sorts the table initially when the page loads) and I get the click event when a column is clicked. But, I think there might be a bug in Event.element(event) from the prototype.js code because I''m not getting back the source element of the event (or I''m just using it wrong). Anyone have any ideas on that? --Tom _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs -- Eric Fleming efleming@gmail.com
On Aug 13, 2005, at 9:21 AM, Andrew Otwell wrote:> > >> I''ve put together a little library to provide sortable tables. It is >> heavily copied from http://www.kryogenix.org/code/browser/sorttable/ >> (mentioned in the Wish List) but has been modified to match the same >> form as the prototype.js library >> > > This doesn''t seem to work at all on Safari. I''m unable to check the > kryogenix version right now, his site''s not responding.This is still happening. I doubt it''ll help, but here''s a version I created a while back that works in Safari. http://raibledesigns.com/page/rd?anchor=client_side_sorting_with_the Matt