[Dbix-class] Pagination Troubles
fREW Schmidt
frioux at gmail.com
Mon Feb 9 19:02:44 GMT 2009
Thanks Jason! Here is the complete function if anyone is curious:
sub basic_data {
> my $self =3D shift;
> my $params =3D shift;
> my $table =3D $params->{table};
> my $search =3D $params->{search};
> my $columns =3D $params->{columns};
> my $rows =3D $self->query->param('limit') || 25;
>
# our framework gives us an amount to skip instead of a page number.
> my $page =3D ($self->query->param('start')?(
> $self->query->param('start')/$rows + 1 ):1);
# this is a little kludgey, but we must have a sort, so if there isn't
> one we just sort by id.
>
my $order_by =3D
> ($self->query->param('sort')?$self->query->param('sort').'
> '.$self->query->param('dir'):'id');
> use DBIx::Class::ResultClass::HashRefInflator;
> my $rs_full =3D $self->schema()->resultset($table)->search($search,{
> order_by =3D> $order_by,
> columns =3D> $columns,
> });
> my $data =3D { data =3D> []};
> $data->{total} =3D $rs_full->count;
> my $rs =3D $rs_full->search({},{
> rows =3D> $rows,
> page =3D> $page,
> });
> $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
> while (my $operation_code =3D $rs->next() ) {
> push @{$data->{data}}, $operation_code;
> }
> return $self->json_body($data);
> }
>
-- =
fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090209/56b=
3504b/attachment.htm
More information about the DBIx-Class
mailing list