NAME
HTML::FormFu::ExtJS::Grid
DESCRIPTION
If you want to present data which has been submitted by a form in a ExtJS grid chose this module. Simply use it instead of HTML::FormFu or HTML::FormFu::ExtJS.
METHODS
grid_data
This methods returns data in a format which is expected by ExtJS as perl object. You will want to serialize it with JSON and send it to the client.
$form->grid_data($data);
$data
can be a DBIx::Class::ResultSet object, an arrayref of DBIx::Class::Row objects or a simple perl object which should look like this:
$data = [{fieldname1 => 'value1', fieldname2 => 'value2'}];
The returned perl object looks something like this:
{
'metaData' => {
'fields' => [
{
'name' => 'artistid',
'type' => 'string'
},
{
'name' => 'name',
'type' => 'string'
}
],
'totalProperty' => 'results',
'root' => 'rows'
},
'rows' => [
{
'artistid' => '1',
'name' => 'Caterwauler McCrae'
},
{
'artistid' => '2',
'name' => 'Random Boy Band'
},
{
'artistid' => '3',
'name' => 'We Are Goth'
}
],
'results' => 3
}
The metaData
property does some kind of magic on the client side. Read http://extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader for more information.
Sometimes you need to send a different number of results back to the client than there are rows (i.e. paged grid view). Therefore you can override every item of the perl object by passing a hashref.
$form->grid_data($data, {results => 99});
This will set the number of results to 99.
grid_data
will call all deflators specified in the form config file.- Select elements will not display the acutal value but the label of the option it refers to.
- If you are passing DBIx::Class objects and the field is a has_many or many_to_many relationship it will call
count
on that.
record
record
returns a JavaScript string which creates a Ext.data.Record
object from the $form
object. This is useful if you want to create Ext.data.Record
objects dynamically using JavaScript.
You can add more fields by passing them to the method.
$form->record();
# Ext.data.Record.create( [ {'name' => 'artistid', 'type' => 'string'},
# {'name' => 'name', 'type' => 'string'} ] );
$form->record( 'address', {'name' => 'age', type => 'date'} );
# Ext.data.Record.create( [ {'name' => 'artistid', 'type' => 'string'},
# {'name' => 'name', 'type' => 'string'},
# {'name' => 'age', 'type' => 'date'},
# 'address' ] );
To get the inner arrayref as perl object, call $form->_record()
.
SEE ALSO
COPYRIGHT & LICENSE
Copyright 2008 Moritz Onken, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.