Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Alphabetical Pagination/Navigation

Is there a rails plugin that will do alphabetical pagination/navigation?

I have a very large data set and would prefer something that gave users a more direct navigation cue in addition to 1..2...3...4...5 pagination.

I could code it myself but was wondering if there was a decent plugin out there already that would do it for me.

like image 296
srboisvert Avatar asked Feb 16 '09 22:02

srboisvert


2 Answers

Why can you not have the alphabet for which you want to see the results to, passed as a parameter? And then paginate on the results? That is,

# show results of params[:alphabet] alphabet
@results = fetch_results(params[:alphabet]) 
# Use Will Paginate to fetch results internally and give a condition that 
# fetches results starting with the passed alphabet.

And show paginated results (numbered) using <%= will_paginate @results %> on the view.

like image 147
Chirantan Avatar answered Nov 08 '22 05:11

Chirantan


I implemented something like that a while ago (based on the popular will_paginate plugin): Implementing Grouped Links. It can generate links like:

alt text http://www.hennessynet.com/blog/wp-content/uploads/2008/09/letters.png

Note: I haven't updated this to use named scopes (as I didn't need them). If you feel like adding support for them, please send me a patch.

like image 39
Denis Hennessy Avatar answered Nov 08 '22 03:11

Denis Hennessy