Data Grid

50 views
Skip to first unread message

Emanuele Preda

unread,
Aug 2, 2012, 7:27:17 PM8/2/12
to perl-for...@googlegroups.com
First of all: thank you, this module is more than what I could find in my best dreams. It saves a LOT of time in a very boring task like building forms.

I use it together with Template Toolkit, and I need now to make a table containing a data grid, i.e.:

Quantity             |       Description       | Price
 --------------------------------------------------------------------------------
 [% qty1.field %] | [% desc1.field %] | [% price1.field %]
 [% qty2.field %] | [% desc2.field %] | [% price2.field %]
 [% qty3.field %] | [% desc3.field %] | [% price3.field %]
..

Any ideas on how I can I name the fields to be able to use the FOREACH statment in TT?

Can I try to name the fields like fldx.qty, fldx.desc and pass an array with fld1, fld2, fld3 values?
I don't think I can repeat the same name for all the lines.


Thanks in advance!

Emanuele Preda

Emanuele Preda

unread,
Aug 2, 2012, 9:15:07 PM8/2/12
to perl-for...@googlegroups.com
I found it!
in the template I did this:

[% FOREACH row = rows %]

<tr>
      <td style="text-align: left; vertical-align: top;" align="right">
[% rqty = row _ 'qty' %][% form.field.$rqty.field %] </td>
      <td> [% rcod = row _ 'cod' %][% form.field.$rcod.field %] </td>
      <td> [% rdes = row _ 'des' %][% form.field.$rdes.field %] </td>
      <td style="vertical-align: top;"> [% rprice = row _ 'price' %][% form.field.$rprice.field %] </td>
    </tr>

[% END %] 

while in the code:

# $m is a ref to an array of arrays of 4 elements (my cart)
my $ft = $form->template();  # takes the current hashref of template

foreach my $el (@{$m})     # each $el contains a ref to the 4 fields of each row
{
push (@id, 'fld'.$i);   # the array needed for TT to recall the elements 
$form->field(name => 'fld'.$i.'qty', value=>$$el[0]);
$form->field(name => 'fld'.$i.'cod', value=>$$el[1]);
$form->field(name => 'fld'.$i.'des', value=>$$el[2]);
$form->field(name => 'fld'.$i.'price', value=>$$el[3]);

$i++;
}
$ft->{'data'}->{'rows'} = \@id;    # I pass to TT the array

This creates a grid of elements, each with its own unique name.

This module and TT together are really great and powerful.

Thank you so much for this wonderful work!!!!!!!!!!!
Reply all
Reply to author
Forward
0 new messages