Class AdminPageFramework_FieldType_table
The Table field type generates table outputs from given an array.
Field Definition Arguments
Field Type Specific Arguments
- data - (required, array|string) An array representing a table. When an associative array is passed, all the rows will consist of two columns of key-value pairs, suitable to inspect array contents. When a string value is passed, the value will be rendered. This is useful when creating FAQ with multiple tables.
- stripe - (optional, boolean) Whether to make the table rows striped or not.
- collapsible - (optional, boolean|array) whether to contain
the table in a collapsible container. When an array is passed, the following
sub-arguments are accepted.
- active - (optional, boolean) Whether to open the container by default.
- animate - (optional, integer) The animation speed.
- escape - (optional, boolean) Whether to to escape HTML characters or not. When the inspecting data contains HTML code that shouldn't be rendered as HTML elements, turn this on; the code will be displayed instead of actual HTML elements.
- caption - (optional, string) The table title. When the
collapsible
argument is true, this is required. - header - (optional, array) Table header items which serving as column titles placed at the top of the table.
- footer - (optional, array|string) Table footer items placed
at the bottom of the table. When
USE_HEADER
is set and the<span class="php-keyword2">header</span>
argument is set, the same value as the<span class="php-keyword2">header</span>
argument is used.
Examples
Creating a Basic Table
array( 'field_id' => 'basic', 'type' => 'table', 'data' => array( array( 'Hat', 'ZA2001' ), array( 'Jacket', 'ZB2002' ), array( 'Shoe', 'ZB2003' ), ), )
Adding Header and Footer
array( 'type' => 'table', 'header' => array( 'Type', 'Code', 'Price' ), 'footer' => array( 'Total', '', 180 ), 'data' => array( array( 'Hat', 'ZA2001', 20, ), array( 'Jacket', 'ZB2002', 50, ), array( 'Shoe', 'ZB2003', 40, ), array( 'Watch', 'ZB2004', 70, ), ), )
Adjusting Layout with Custom Attributes
array( 'field_id' => 'attributes', 'type' => 'table', 'title' => __( 'Attributes', 'admin-page-framework-loader' ), 'header' => array( 'Type', 'Code', 'Price' ), 'footer' => array( 'Total', '', 110 ), 'data' => array( array( 'Hat', 'ZA2001', 20, ), array( 'Jacket', 'ZB2002', 50, ), array( 'Shoe', 'ZB2003', 40, ), ), 'attributes' => array( 'th' => array( // zero-based second column 2 => array( 'style' => 'text-align: right; width: 10%;' ), ), 'td' => array( // zero-based second column 2 => array( 'style' => 'text-align: right; width: 10%;' ), ), ), )
Inspecting Array Data
To check array contents, pass multi-dimensional associative array to thedata
argument.
array( 'field_id' => 'associative', 'type' => 'table', 'title' => __( 'Associative', 'admin-page-framework-loader' ), 'data' => array( "foo" => "bar", 42 => 24, "multi" => array( "dimensional" => array( "element" => "foo" ) ) ), )
Using Table Caption
With thecaption
argument, the title title can be set.
array( 'field_id' => 'wide_table', 'type' => 'table', 'show_title_column' => false, 'data' => array( 'first_release' => '1995', 'latest_release' => '7.3.11', 'designed_by' => 'Rasmus Lerdorf', 'description' => array( 'extension' => '.php', 'typing_discipline' => 'Dynamic, weak', 'license' => 'PHP License (most of Zend engine under Zend Engine License)' ) ), 'caption' => __( 'Caption', 'admin-page-framework-loader' ), )
Table Header and Footer for Associative Arrays
Since associative array tables consist of only two columns in each row and the first column width has a set width, when you set a header and footer for those tables, set a key-value.array( 'field_id' => 'table_header_and_footer', 'type' => 'table', 'data' => array( 'first_release' => '1991', 'latest_release' => '3.8.0', 'designed_by' => 'Guido van Rossum', 'description' => array( 'extension' => '.py', 'typing_discipline' => 'Duck, dynamic, gradual', 'license' => 'Python Software Foundation License' ) ), 'title' => __( 'Footer and Header for Associative', 'admin-page-framework-loader' ), // for associative arrays, set key-value pairs to the header and footer 'header' => array( 'Custom Header Key' => 'Custom Header Value' ), 'footer' => array( 'Custom Footer Key' => 'Custom Footer Value' ), )
Placing Table in a Collapsible Container
array( 'field_id' => 'collapsible', 'title' => __( 'Collapsible', 'admin-page-framework-loader' ), 'type' => 'table', 'caption' => 'WordPress', 'collapsible' => true, 'data' => array( 'foo' => 'bar' ), )
Creating Simple FAQ
array( 'field_id' => 'simple_faq', 'type' => 'table', 'collapsible' => true, 'caption' => 'What day is it today?', 'data' => sprintf( 'Today is %1\$s.', date( 'l' ) ), array( 'caption' => 'What time is it now?', 'data' => sprintf( 'Now is %1\$s.', date( get_option( 'date_format' ) ) ), ) )
For common field definition arguments, see AdminPageFramework_Factory_Controller::addSettingField()
.
Package: AdminPageFramework\Common\Form\FieldType
Since: 3.9.0
Image: http://admin-page-framework.michaeluno.jp/image/common/form/field_type/table.png
Located at factory/_common/form/field_type/table/AdminPageFramework_FieldType_table.php
Since: 3.9.0
Image: http://admin-page-framework.michaeluno.jp/image/common/form/field_type/table.png
Located at factory/_common/form/field_type/table/AdminPageFramework_FieldType_table.php
Methods summary
protected
array
|
#
getEnqueuingScripts( )
|
protected
|
Magic methods summary
Properties summary
public
array
|
$aFieldTypeSlugs |
#
Defines the field type slugs used for this field type. |
protected
array
|
$aDefaultKeys |
#
Defines the default key-values of this field type. |