Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Server-side processing?

by frank1 (Scribe)
on Feb 13, 2024 at 17:55 UTC ( [id://11157680]=perlquestion: print w/replies, xml ) Need Help??

frank1 has asked for the wisdom of the Perl Monks concerning the following question:

I need some help on server side processing for datatable, i want to be able to handle over 300k records, and i was advised to use server side processing method

its my first time server side processing trying in perl

my main point is that, if i have PERL Script

my $INFO = $DBH->prepare("SELECT SND.ACC, M.ID, M.FULLNAME FROM U_REC as M JOIN U_USERS as SND ON SND.ACC = M.ID WHERE CASE WHEN (SELECT SUM(st +atus = ?) FROM U_REC) > 0 THEN M.status = ? ELSE M.status = ? OR M. +status = ? OR M.status = ? END ORDER BY created ASC"); $INFO->execute('new', 'ne1', 'ne2', 'ne3', 'ne4'); my (@data,$ACC,$ID,$FULLNAME); foreach (@data = $INFO->fetchall_arrayref()) { $ACC = $data[0]; $ID = $data[1]; $FULLNAME = $data[2]; }

Then how do i return results to html

<!doctype html> <html> <head> <meta charset="UTF-8"> <title></title> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.ne +t/v/bs-3.3.7/jq-3.3.1/dt-1.10.18/datatables.min.css"/> <script type="text/javascript" src="https://cdn.datatables.net/v/bs/jq +-3.3.1/dt-1.10.18/datatables.min.js"></script> <script type="text/javascript" src="https://stackpath.bootstrapcdn.com +/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script> <script> jQuery(function($){ $("#table_id").DataTable({ "processing": true, "serverSide": true, "ajax": "general/events/file.pl" }); }); </script> </head> <body> <h1>sample dataTable</h1> <table id="table_id" class="table table-hover"> <thead> <tr> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td>Ex: (10123) #ID goes here</td> <td>Ex: (Jane Deo) #Fullname goes here</td> </tr> <tr> <td>Ex: (20911) #ID goes here</td> <td>Ex: (John Deo) #Fullname goes here</td> </tr> </tbody> </table> </body> </html>

Replies are listed 'Best First'.
Re: Server-side processing?
by marto (Cardinal) on Feb 14, 2024 at 10:27 UTC

      i have read some articles and saw some examples, this is what i also need to return data from perl backend as JSON and print out in html

        Are you saying you now know what you need to do?

Re: Server-side processing?
by Corion (Patriarch) on Feb 14, 2024 at 07:21 UTC

    I don't know much about jQuery, but the general idea is to create the table content in Perl (using a templating system, like Template::Toolkit, HTML::Template or maybe Mojolicious), and then send that to the browser.

    Something like the following:

    use Mojolicious::Lite; get '/' => sub { my( $c ) = @_; # fake fetch rows from database # my $sth = $dbh->prepare( "select id, name from mytable order by +id" ); # my @rows = $sth->fetchall_arrayref( {} ); my @rows = ( { id => 10123, , name => 'Jane Doe' }, { id => 20911, , name => 'John Devo' }, ); $c->stash( rows => \@rows ); $c->render( 'index' ); } __DATA__ @@index.html.ep <!DOCTYPE html> <html> <body> <table> <thead><tr><th>ID</th><th>Name</th></tr></thead> % for my $row (@$rows) { <tr><td><%= $row->{id} ></td><td><%= $row->{name} </td></tr> % } </table> </body> </html>
Re: Server-side processing?
by karlgoethebier (Abbot) on Feb 15, 2024 at 11:45 UTC

    Using bootstrap? See here for further information.

    «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-05-21 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found