Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Need help to guide how to create client sort table ( mojo.template.array.autoindex.sortable.pl )

by Anonymous Monk
on Jun 25, 2013 at 01:28 UTC ( [id://1040509]=note: print w/replies, xml ) Need Help??


in reply to Need help to guide how to create client sort table

And here it is, if JQuery::TableSorter were added I'd look for (jquery/css) ways to disable the uparrow/downarrow links if user has javascript on, so the browser does the work, not perl

I run this as perl mojo.template.array.autoindex.sortable.pl daemon --listen http://localhost:80/

The some variable names are dumb :) The subs then mojo stuff before __DATA__ order is intentional, see Mojolicious::Lite

#!/usr/bin/perl -- # Automatically enables "strict", "warnings", "utf8" and Perl 5.10 fea +tures use Mojolicious::Lite; sub my_sorted_fudge { ## has no pageination :P my( $sortorder, $sortindex ) = @_; $sortorder ||= ''; #~ $sortindex ||= 0; $sortindex = int $sortindex ; my %order = ( 'ascend' => sub { $$a[ $sortindex ] cmp $$b[ $sortindex ] }, 'descend' => sub { $$b[ $sortindex ] cmp $$a[ $sortindex ] }, '' => undef, # default sort order, none ); my $byorder = $order{ $sortorder }; my @th = ( "Ro", "Sham", "Bo" ); my @array = ( ["i", "f", "i"], ["q", "s", "n"], ["u", "g", "m"], ["j", "r", "n"], ["w", "r", "j"], ["q", "q", "n"], ["x", "p", "p"], ["o", "h", "b"], ["g", "x", "a"], ); $byorder and @array = sort $byorder @array; ## don't sort by defau +lt return \@array, \@th ; } sub mojo_index { my $self = shift; my $sortorder = $self->param('sortorder') || ''; my $sortindex = $self->param('sortindex') || 0; my( $rah, $rahth ) = my_sorted_fudge( $sortorder, $sortindex ); return $self->render( ray => $rah, rayth => $rahth, sortindex => $sortindex, sortorder => $sortorder, title => 'the sortening', ); } ## .ep templates are auto_escape <%= by default / XML escaped result get '/' => \&mojo_index => 'index';;; app->start;
__DATA__ @@ index.html.ep % layout 'green'; %= content content => begin <table border="1"> <thead> <tr> % for my $thix ( 0 .. $#$rayth ){ <th> <%# uparrow =%> <a href="/?sortorder=ascend;sortindex=<%= $thix %> +">&#8593;</a> <%= $$rayth[$thix] =%> <%# downarrow =%> <a href="/?sortorder=descend;sortindex=<%= $thix % +>">&#8595;</a> </th> % } </tr> </thead> <tbody> % for my $rai ( @$ray ) { <tr> % for my $cel ( @$rai ){ <td> <%= $cel =%> </td> % } </tr> % } </tbody> </table> % if( $sortorder and defined $sortindex ){ <div id="sortorderdesc"> * sortorder( <%= $sortorder %>) by sortindex( <%= $sortindex %> aka <%= $$rayth[ $sortindex ] %> ) </div> % } % end @@ layouts/green.html.ep <html> <head> <title><%== title %></title> </head> <body bgcolor="lightgreen"> <%= content %> </body> </html>
  • Comment on Re: Need help to guide how to create client sort table ( mojo.template.array.autoindex.sortable.pl )
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Need help to guide how to create client sort table ( mojo.template.array.autoindex.sortable.pl )
by GordonLim (Acolyte) on Jun 26, 2013 at 07:43 UTC
    Thanks Anonymous Monk for provided me such long code. I will try this in next week due to some reason cannot install Mojolicious::Lite by this week. :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1040509]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-24 02:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found