[Catalyst] Alphabetical Paging based on First Letter
I would like to implement a page navigation based on the first letter of the items, e.g. first letter of last names, so all last names with 'A' will display when you click on 'A' (instead of page 1) and all last names starting with 'M' appear when you click on 'M' and so on... Only the initials that are actually present in the database should be displayed for paging navigation, so if there is NO last name starting with 'X', 'X' shouldn't show up in the navigation line. How would you realize something like this in Catalyst? I couldn't find a pertinent module on CPAN. I have (happily) used Data::Page before, but that only works for numerical paging, doesn't it? Thanks in advance, Matt ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Alphabetical Paging based on First Letter
On Feb 27, 2008, at 3:50 PM, Matt Knesi wrote: I would like to implement a page navigation based on the first letter of the items, e.g. first letter of last names, so all last names with 'A' will display when you click on 'A' (instead of page 1) and all last names starting with 'M' appear when you click on 'M' and so on... Only the initials that are actually present in the database should be displayed for paging navigation, so if there is NO last name starting with 'X', 'X' shouldn't show up in the navigation line. I've done this with a dictionary application. You could do a relationship to a letter. So say name has_one letter, letter has_many names. Or what I've done a couple of times is make letter a field in the target table (word for me, name for you) and just keep the letter or # for a leading number/special and make it an index so it's fast to lookup. -Ashley ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Alphabetical Paging based on First Letter
On Wed, Feb 27, 2008 at 6:01 PM, Ashley [EMAIL PROTECTED] wrote: On Feb 27, 2008, at 3:50 PM, Matt Knesi wrote: I would like to implement a page navigation based on the first letter of the items, e.g. first letter of last names, so all last names with 'A' will display when you click on 'A' (instead of page 1) and all last names starting with 'M' appear when you click on 'M' and so on... Only the initials that are actually present in the database should be displayed for paging navigation, so if there is NO last name starting with 'X', 'X' shouldn't show up in the navigation line. I've done this with a dictionary application. You could do a relationship to a letter. So say name has_one letter, letter has_many names. Or what I've done a couple of times is make letter a field in the target table (word for me, name for you) and just keep the letter or # for a leading number/special and make it an index so it's fast to lookup. I'm not a fan of munging data unless there's a need for high performance. Unless this is a gigantic table you could probably just do: # I didn't syntax test this, ymmv my $rs = $schema-resultset('Person')-search(undef, { select = \'SUBSTR(name, 1, 1)', as = 'letter', group_by= \'SUBSTR(name, 1, 1) }); my @letters = $rs-get_column('letter')-all(); $c-stash-{'letters'} = [EMAIL PROTECTED]; and in TT: [% FOREACH letter = letters %]a href...[% letter %]/a[% END %] Then you'd have your list and not have to do any column adding or name munging. I'd also add a custom resultset and a method that did something like: sub starts_with { my ($self, $str) = @_; return $self-search({ name = { '-like' = $str\% } }); } So that you can do $rs-starts_with($c-req-param('letter')). -- Cory 'G' Watson http://www.onemogin.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/