Mojolicious::Plugin::DataTables
Usage
# Mojolicious
$self->plugin('DataTables');
# Mojolicious::Lite
plugin 'DataTables';
helper sql => sub { state $pg = Mojo::Pg->new('postgresql://postgres@/test') };
get '/users_table' => sub {
my $c = shift;
my $sql = $c->sql;
my $dt_ssp = $c->datatable->ssp(
table => 'users',
sql => $sql,
options => [
{
label => 'UID',
db => 'uid',
dt => 0,
},
{
label => 'e-Mail',
db => 'mail',
dt => 1,
},
{
label => 'Status',
db => 'status',
dt => 2,
},
]
));
$c->render(json => $dt_ssp);
};
@@ template.html.ep
<html>
<head>
<%= datatables_js %>
<%= datatables_css %>
</head>
<body>
<table id="users_table" class="display" style="width:100%">
<thead>
<th>UID</th>
<th>e-Mail</th>
<th>Status</th>
</thead>
</table>
<script>
jQuery('#users_table').DataTable({
serverSide : true,
ajax : '/users_table',
});
</script>
</body>
</html>
Installation
To install this module type the following:
perl Makefile.PL
make
make test
make install
Copyright
Copyright (C) 2020-2021 by Giuseppe Di Terlizzi