Yeah, there’s nothing built-in. But take a look at the code for the
sorting_helper, it’s only 20-25 lines of code for a general purpose
sorter. It goes to show how easy this sort of thing is to accomplish
in Rails. I would probably never bother with this sorter code since
it’s trivially fast to implement exactly what I want.
Tks Gabriel - you don’t have a site I can have a look at? - I’d be
interested in seeing how people have laid-out their sorting links
I use sort_helper - www.crmonrails.com - go to the leads or orders list
and click on any of the column headers. Don’t have it on the activities
list. Not much data in that demo app, but it will give you an idea of
how I did it.
got it Michael thanks - cool - what did you use on the site for the
“page
forward” / “jump to last page”? Was it the rails paging mechanism?
Here is the code that I put in the application helper file
(application_helper.rb) for the sort colums and for the pagination that
you ask about. I don’t pretend to be an optimization guru - so I’m sure
there is a better way to achieve this. However, this did the trick for
me and is reused across my views.
I’m sorry - forgot to answer your question: Yes, it is using the Rails
pagination object which, if you read other posts, may not be the wisest
thing to do (performance)! I don’t plan on having millions of rows
so it will be fine for me (I think) and I strongly suspect that by the
time it becomes an issue then the core guys will have figured out how to
keep pagination and make it perf friendly. If they don’t then by the
time I have millions of rows I’ll also have other resources available to
help figure it out!
if you’re ever looking to use ajax to do table sorting there’s a few
resources that i’ve picked up over the last few months.
This first one is just a tutorial that walks through building your own
helpers for it. pretty sure it degrades well if the user doesn’t have
javascript too, so it’ll prlly be easy to figure out either way.
I haven’t actually used this next one in my projects, but it looks
really nice. I’ve played around with it some and it seems like it
requires a little bit more of a learning curve to actually have it do
just what I want. But maybe it can help you.
This is trying to do a “new.merge(old)” however it seems that the merge
works the other way round in terms of ensuring that the new settings
override the old. I tried the following and it seemed to work: