NAME

JQuery::DataTables::Heavy::DBI - jquery datatable server side processing by DBI

SYNOPSIS

  use JQuery::DataTables::Heavy::DBI;
  use DBIx::Handler;
  use JSON::XS;
  use Plack::Request;

  my $handler = DBIx::Hander->new( $dsn, $user, $password, \%attr );
  my $req= Plack::Request->new($env);

  my $dt = JQuery::DataTables::Heavy::DBI->new(
      dbh => $handler->dbh,
      table  => 'some table or \$sql',
      fields => [qw(fields of some table)],
      param => $req->parameters;
      decorate_aaData => sub {
          my ($aaData) = @_;
          foreach my $hash (@$aaData){
              $hash->{img} = q{<img src="/images/details_open.png">};
          }
      },
  );
  my $to_json = $dt->table_data;
  to_json($to_json);

DESCRIPTION

Method

new

dbh required

set database handle

table required

set table name (Str). Or sql (ScalarRef) like bellow

  (
    SELECT
      a AS field_a
      IF ( b IS NULL, 0, b ) AS field_b
    FROM
      some_table
    JOIN
      other_table
    ON
      other_table.col_a = some_table.id
  ) AS table_alias

SQL is usefull when you need JOIN.

fields required

set database column

param required

set HTTP Request Parameters

=decorate_aaData optional

set code ref for decorate aaData

table_data()

 Return table content as json. Evaluates query for global filtering and
 ordering information. The database is queried to collect the data.
  

PREREQUISITES

Moo

Author

 Yusuke Watase <ywatase@gmail.com>