Form::...:table(3pm)

πŸ“¦
version 2.5.0 Β· 2 versions
, in ubuntu jammy

πŸ’– Embperl::Form::Control::table πŸ’–

okay bestie, listen up β€” this is the Embperl::Form::Control::table page from the User Contributed Perl Documentation, and it's giving table that gets its data from an array of arrays or an array of hashs. yes, "hashs". we don't fix that, we love her. 🫢


✨ NAME ✨

Embperl::Form::Control::table β€” a table which gets data from an array of arrays or an array of hashs πŸ’…


🌸 SYNOPSIS 🌸

{
type => 'table',
text => 'blabla',
columns => [['foo', 'Foo item'], 'bar'],
}

πŸ¦‹ DESCRIPTION πŸ¦‹

So the vibe here is: this class is a base class, and you use it to create a table control inside an Embperl Form. That's literally its whole job. πŸ‘‘

Wanna know how to specify parameters? Go look at Embperl::Form, she has the answers.

In most cases you're gonna need to overwrite this class and call the method show_table. And show_table takes an arrayref of hashrefs or an arrayref of arrays as its parameter, and that's what gets used as the data to display. no cap.

BUT β€” and this is the slay part β€” if you already have this data sitting directly in %fdat, you can just use this control directly. no overwriting needed, main character behavior fr fr. ✨

πŸŽ€ PARAMETER πŸŽ€

type

Needs to be 'table'. that's it. that's the requirement. periodt.

text

This one gets used as the label for the control. 🏷️

columns

An arrayref that contains arrayrefs, and those inner arrayrefs are the definition of the column names. This lets you specify multiple rows per data entry β€” iconic.

Each column definition is either:

  • the key name in the data hashref, or
  • an arrayref with the name in the hashref and the text to display as the heading

Example time, bestie:

[
 [['email', 'E-Mail Address'], ['phone', 'Phone']],
 [['foo', 'Foo'], ['bar', 'Bar']],
]

so email and phone get displayed on the first line with the headings 'E-Mail Address' and 'Phone', and foo and bar get displayed on the second line for each entry. cute, right? πŸ“

Oh and β€” if your data is an array of arrays instead, you have to specify the array index instead of the hash key name. different data shape, different rules, iykyk.

Also!! You can add extra info to an entry. One entry might contain these things:

  • 0 β€” key into the data hashref
  • 1 β€” text to display
  • 2 β€” Colspan (how many columns this cell should span)
  • 3 β€” if set, a control is displayed instead of text. Must contain: radio,<name>,<value> or checkbox,<name>,<value>
  • 4 β€” display as a link. This item contains the name of the key in the data hashref that holds the href.
  • 5 β€” target for the link
  • 6 β€” name of a filter function. The value of the cell gets processed through this filter. Filter functions are passed as a hashref of subs in the parameter 'filters'.

line2

An arrayref with names, and the values of those names get concated and displayed below each entry. yes, "concated". we're keeping it. πŸ’œ

filters

A hashref of coderefs that holds your filter functions. πŸ’…

Here's an example showing one filter called 'date' which passes the data through the perl function format_date. The value is passed as the first argument to the filter function. The second argument is the column description (see above), the third argument is the row data, and the last argument is the current Embperl request record. so many arguments, so much power. πŸ”₯

filters =>
      {
      'date' => sub
          {
          return format_date ($_[0]) ;
          }
      }

πŸ‘‘ Author πŸ‘‘

G. Richter (richter at embperl dot org)


🌈 See Also 🌈

perl(1), Embperl, Embperl::Form


πŸŽ€ and that's the whole page bestie, you ate it, go build your table πŸ’–

This page came to you courtesy of perl v5.34.0 and it was dated 2022-02-06, and yes the man page header calls itself Form::...:table(3pm) β€” the ellipsis is doing a little mystery moment, we respect it. mwah, bye!! πŸ’…βœ¨

πŸ“¦ where this page comes from