The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

CatalystX::CRUD::YUI::DataTable - YUI DataTable objects

SYNOPSIS

 my $datatable = $yui->datatable( 
            results     => $results,    # CX::CRUD::Results or CX::CRUD::Object
            controller  => $controller, 
            form        => $form,
            method_name => $rel_info->{method},
            col_names   => $form->metadata->field_methods,
 );
  
 $datatable->serialize;  # returns serialized results
 $datatable->count;      # returns number of rows
 

METHODS

new( opts )

Create a YUI DataTable object. You usually call this via CatalystX::CRUD::YUI->datatable( opts ).

opts should include:

results

The results object passed in. May be either a CatalystX::CRUD::Results instance or CatalystX::CRUD::Object instance.

If a Results instance, each object in the Results set will be serialized.

If a Object instance, each object returned by method_name will be serialized.

form

The form object should be an instance of the Form class that corresponds to the data being serialized. In the case where results isa CatalystX::CRUD::Results object, form should be a Form corresponding to the object class in CatalystX::CRUD::Results->results(). In the case where results isa CatalystX::CRUD::Object, form should be a Form corresponding to the foreign object class represented by method_name.

controller

The controller object should be the governing controller for the objects being serialized, i.e., the controller governing form.

The new DataTable has the following accessors available:

pk

The primary key of the table that results represents.

columns

An arrayref of column hashrefs. YUI DataTable API requires these.

url

The url for fetching JSON results.

A hashref of foreign key information.

col_filter

An arrayref of column names. # TODO used for??

col_names

An arrayref of column names. Defaults to form->metadata->field_methods.

data

An arrayref of hashrefs. These are serialized from results.

count

The number of items in data.

counter

User-level accessor. You can get/set this to whatever you want.

NOTE: If you pass a CatalystX::CRUD::Object instance as results to new(), the object must implement a primary_key_uri_escaped() method that conforms to the syntax defined by CatalystX::CRUD::Controller make_primary_key_string(). See Rose::DBx::Object::MoreHelpers for one example.

column( field_name )

Return the column hashref meta for field_name. The hashref has 3 keys: key, label, and sortable.

serialize

Returns DataTable as array ref of hash refs, suitable for conversion to JSON or other transport type.

AUTHOR

Peter Karman, <karman@cpan.org>

BUGS

Please report any bugs or feature requests to bug-catalystx-crud-yui@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

ACKNOWLEDGEMENTS

The Minnesota Supercomputing Institute http://www.msi.umn.edu/ sponsored the development of this software.

COPYRIGHT & LICENSE

Copyright 2008 by the Regents of the University of Minnesota.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.