Overview

Namespaces

  • Rundiz
    • DataTable

Classes

  • Database
  • DataTable
  • Overview
  • Namespace
  • Class

Class DataTable

Data table class for generate table with header, footer, data list, bulk actions, pagination.
This class is copied from the WordPress list table class.

Namespace: Rundiz\DataTable
Author: Vee W.
Located at DataTable/DataTable.php
Methods summary
public
# __construct( array $config = [] )

DataTable class constructor.

DataTable class constructor.

Parameters

$config
Available config key: [pdoconfig [dsn], [username], [password], [options]] (see more at http://php.net/manual/en/pdo.construct.php)
public
# __destruct( )

DataTable class de-constructor.
This method will be called reset() method to clear everything to its default values.

DataTable class de-constructor.
This method will be called reset() method to clear everything to its default values.

protected string
# columnCheckbox( object $row )

Column checkbox.

Column checkbox.

Parameters

$row
Data from PDO in each row from fetchAll() method.

Returns

string
Return checkbox element with value. Use return, not echo.
protected string
# columnDefault( object $row, string $column_unique_name )

Column default.
Return content for columns by default (no special, the special columns need to create their own column with unique name).
For special column method. Example: You have unique name as "time". The special column method name will be columnTime($row).

Column default.
Return content for columns by default (no special, the special columns need to create their own column with unique name).
For special column method. Example: You have unique name as "time". The special column method name will be columnTime($row).

Parameters

$row
Data from PDO in each row from fetchAll() method.
$column_unique_name
The column unique name.

Returns

string
Return column content. Use return, not echo.
public
# display( )

Display the data table.

Display the data table.

protected array
# getBulkActions( )

Get bulk actions.

Get bulk actions.

Returns

array
Return array of bulk action value and text to display in the select box. Example: ['delete' => 'Delete'].
protected array
# getColumnClasses( object $row, string $column_unique_name = '' )

Get column classes.
This class will be add in to

th

or

td

in the

tbody

.

Get column classes.
This class will be add in to

th

or

td

in the

tbody

.

Parameters

$row
Data from PDO in each row from fetchAll() method.
$column_unique_name
Column unique name for check.

Returns

array
Return classes in array value. [class_name1, class_name2].
protected array
# getColumnFooterClasses( string $column_unique_name = '' )

Get column footer classes.
This class will be add in to

th

or

td

in the

tfoot

.

Get column footer classes.
This class will be add in to

th

or

td

in the

tfoot

.

Parameters

$column_unique_name
Column unique name for check.

Returns

array
Return classes in array value. [class_name1, class_name2].
protected array
# getColumnHeaderClasses( string $column_unique_name = '' )

Get column header classes.
This class will be add in to

th

or

td

in the

thead

.

Get column header classes.
This class will be add in to

th

or

td

in the

thead

.

Parameters

$column_unique_name
Column unique name for check.

Returns

array
Return classes in array value. [class_name1, class_name2].
protected array
# getColumns( )

Get all the table columns to display.

Get all the table columns to display.

Returns

array
Return array key that is unique name and text display in array value. [key (unique name, no need to refer to table field) => text display].
protected integer
# getCurrentPage( )

Get current pagination page number.

Get current pagination page number.

Returns

integer
Return pagination page number.
protected string
# getPrimaryColumn( )

Get primary column from unique name.
If there is "checkbox" unique name in the getColumns() method, it will return the second unique name.
If there is no "checkbox" unique name in the getColumns() method, it will return the first unique name.
You can override this method by set the primary column from unique name from getColumns() method.

Get primary column from unique name.
If there is "checkbox" unique name in the getColumns() method, it will return the second unique name.
If there is no "checkbox" unique name in the getColumns() method, it will return the first unique name.
You can override this method by set the primary column from unique name from getColumns() method.

Returns

string
Return unique name that was set in the getColumns() method.
protected array
# getRowActions( object $row, string $column_unique_name, string $primary_column_name )

Get row actions.
Override this method to set actions for each data row.

Get row actions.
Override this method to set actions for each data row.

Parameters

$row
Data from PDO in each row from fetchAll() method.
$column_unique_name
Column unique name for check.
$primary_column_name
Column name that is primary.

Returns

array
Return row actions as array. Example: [action key => html link, action key2 => html link2]
protected array
# getSortableColumns( )

Get sortable columns.
Override this method to set sortable columns.

Get sortable columns.
Override this method to set sortable columns.

Returns

array
Return array key that is unique name from getColumns() method and array of order by and pre-sorted as ascending (false) or descending (true) in the array value. Example: [key (unique name, no need to refer to table field) => [order_by (refer to table field), false]].
protected array
# getTableAttributes( )

Get

table

attributes (not including class).

Get

table

attributes (not including class).

Returns

array

Return array of attributes in key => value pairs. example: ['data-sortable' => 'true', 'data-sortcolumn' => 'name'] will becomes (

data-sortable="true" data-sortcolumn="name"

).

protected array
# getTableClasses( )

Get

table

classes.

Get

table

classes.

Returns

array
Return array of table classes. [class1, class2, ...]
protected array
# getTbodyAttributes( )

Get table body (

tbody

) attributes (including class).

Get table body (

tbody

) attributes (including class).

Returns

array

Return array of

tbody

attributes. example: ['data-name' => 'true', 'class' => 'my-tbody'] will becomes (

data-name="true" class="my-tbody"

).

protected array
# getTbodyTrTdNodataAttributes( )

Get

tbody
tr
td

attributes where it has no data (including class but do not including colspan).

Get

tbody
tr
td

attributes where it has no data (including class but do not including colspan).

Returns

array

Return array of

tbody
tr
td

attributes. example: ['data-name' => 'true', 'class' => 'my-tbody'] will becomes (

data-name="true" class="my-tbody"

).

protected string
# getText( string $text = '' )

Get text message.
You can override this method to make it translatable.

Get text message.
You can override this method to make it translatable.

Parameters

$text
String key of text message.

Returns

string
Return translated from string key to readable message.
protected array
# getTfootAttributes( )

Get table foot (

tfoot

) attributes (including class).

Get table foot (

tfoot

) attributes (including class).

Returns

array

Return array of

tfoot

attributes. example: ['data-name' => 'true', 'class' => 'my-tfoot'] will becomes (

data-name="true" class="my-tfoot"

).

protected array
# getTfootTrAttributes( )

Get table row of tfoot attributes (including class).

Get table row of tfoot attributes (including class).

Returns

array

Return array of

tfoot
tr

attributes. example: ['data-name' => 'true', 'class' => 'my-tfoot'] will becomes (

data-name="true" class="my-tfoot"

).

protected array
# getTheadAttributes( )

Get table head (

thead

) attributes (including class).

Get table head (

thead

) attributes (including class).

Returns

array

Return array of

thead

attributes. example: ['data-name' => 'true', 'class' => 'my-thead'] will becomes (

data-name="true" class="my-thead"

).

protected array
# getTheadTrAttributes( )

Get table row of

thead

attributes (including class).

Get table row of

thead

attributes (including class).

Returns

array

Return array of

thead
tr

attributes. example: ['data-name' => 'true', 'class' => 'my-thead'] will becomes (

data-name="true" class="my-thead"

).

public
# prepareData( )

Prepare items for listing.

Prepare items for listing.

protected
# preparePagination( )

Prepare pagination. Any customizable of pagination can override by this method.
This data table pagination use Rundiz/Pagination class ( https://github.com/Rundiz/pagination ).

Prepare pagination. Any customizable of pagination can override by this method.
This data table pagination use Rundiz/Pagination class ( https://github.com/Rundiz/pagination ).

Throws

Exception
Throw exception if pagination class is missing.

See

rundiz/pagination See more document at https://github.com/Rundiz/pagination or http://rundiz.com/web-resources/pagination-v3
protected
# printBeforeTableControlsTop( )

Print out before table controls top.

Print out before table controls top.

protected
# printBulkActions( string $which )

Print out bulk actions (select box).

Print out bulk actions (select box).

Parameters

$which
Which position of table controls (top or bottom).
protected
# printColumnHeaders( boolean $is_footer = false )

Display column headers for table. (Echo out.)

Display column headers for table. (Echo out.)

Parameters

$is_footer
Set to true if this column headers is in footer of the table, set to false if it is header of the table.
protected
# printElementAfterTable( )

Display element after end of the table element.

Display element after end of the table element.

protected
# printElementBeforeTable( )

Display element before begins of the table element.

Display element before begins of the table element.

protected
# printExtraTableControls( string $which )

Print extra table controls next to bulk actions but before pagination.

Print extra table controls next to bulk actions but before pagination.

Parameters

$which
Which position of table controls (top or bottom).
protected
# printPagination( string $which )

Print pagination.
To display different pagination style more than customize via pagination's properties, overwrite this method in the sub class.

Print pagination.
To display different pagination style more than customize via pagination's properties, overwrite this method in the sub class.

Parameters

$which
Which position of table controls (top or bottom).
protected
# printRows( )

Loop through data items (rows) and call to print each row.

Loop through data items (rows) and call to print each row.

protected
# printRowsOrPlaceholder( )

Display table rows inside

tbody

or no items place holder if there is no item found.

Display table rows inside

tbody

or no items place holder if there is no item found.

protected
# printSingleRow( object $row )

Print each row and call to print single row columns.

Print each row and call to print single row columns.

Parameters

$row
Data from PDO in each row from fetchAll() method.
protected
# printSingleRowColumns( object $row )

Print row columns.

Print row columns.

Parameters

$row
Data from PDO in each row from fetchAll() method.
protected
# printTableControls( string $which = 'top' )

Print table controls such as bulk actions, pagination or also know as table nav in WordPress.

Print table controls such as bulk actions, pagination or also know as table nav in WordPress.

Parameters

$which
Which position of table controls (top or bottom).
protected string
# renderAttributes( array $attributes = [] )

Render attributes from get***Attributes() methods. (Not echo out just render as string.)

Render attributes from get***Attributes() methods. (Not echo out just render as string.)

Parameters

$attributes
The attributes as array key => value pairs. Example: ['class' => 'table-cell column-pk', 'data-colname' => 'full name'].

Returns

string

Return rendered attributes. Example:

class="table-cell column-pk" data-colname="full name"

.

protected
# renderRowActions( object $row, string $column_unique_name, string $primary_column_name )

Render row actions.

Render row actions.

Parameters

$row
Data from PDO in each row from fetchAll() method.
$column_unique_name
Column unique name for check.
$primary_column_name
Column name that is primary.
public
# reset( )

Reset all properties including database configuration to start data table class from the beginnings.

Reset all properties including database configuration to start data table class from the beginnings.

Properties summary
protected integer $columnsCount

Columns count.

Columns count.

# 0
protected Rundiz\DataTable\Database $Database

The database class connector.

The database class connector.

#
protected array $dataItems

Store data items fetched from database.

Store data items fetched from database.

# []
protected integer $itemsPerPage

Number of items to display per page.

Number of items to display per page.

# 20
protected string $orderQueryName

The order query string name. Its value is column name in the db table. Override this if you have many data table in a page.

The order query string name. Its value is column name in the db table. Override this if you have many data table in a page.

# 'order'
protected Rundiz\Pagination\Pagination $Pagination

The pagination class connector.

The pagination class connector.

#
protected string $paginationQueryName

Pagination query string name. Example: pagination query string like this (?paged=3) the pagination query string name is "paged". You can change this value in case that you have many data table in a page.

Pagination query string name. Example: pagination query string like this (?paged=3) the pagination query string name is "paged". You can change this value in case that you have many data table in a page.

# 'paged'
protected boolean $showFooterColumn

Show footer column or not. (By default it is set to false means not show.)

Show footer column or not. (By default it is set to false means not show.)

# true
protected string $sortQueryName

The sort query string name. Its value basically is ASC, or DESC. Override this if you have many data table in a page.

The sort query string name. Its value basically is ASC, or DESC. Override this if you have many data table in a page.

# 'sort'
protected mixed $tempProperties

Temporary default properties for restore their values when call reset() method.

Temporary default properties for restore their values when call reset() method.

#
protected integer $totalItems

Total items count from database.

Total items count from database.

# 0
API documentation generated by ApiGen