Kotchasan

DataTable extends KBase
in package

Class for managing data presentation from a Model in table format.

Tags
see
https://www.kotchasan.com/

Table of Contents

$actions  : array<string|int, mixed>
If specified, checkboxes and action buttons will be shown.
$addNew  : array<string|int, mixed>
The button for adding new data.
$autoSearch  : bool
Specify the search behavior from the search box.
$buttons  : array<string|int, mixed>
Buttons to be added at the end of each row.
$cols  : array<string|int, mixed>
List of all columns.
$comment  : string
Text, such as Notes, is displayed next to the table.
$commentClass  : string
Note class name
$defaultFilters  : array<string|int, mixed>
List of main query commands for data selection.
$defaultSort  : string|null
The default column name used for sorting.
$enableJavascript  : bool
Enables the usage of DataTable's JavaScript.
$entriesList  : array<string|int, mixed>
Options for the number of entries to be displayed per page.
$filters  : array<string|int, mixed>
Data display filters.
$headers  : array<string|int, mixed>
List of header names for columns.
$hideCheckbox  : bool
Determines whether to hide the checkbox.
$hideColumns  : array<string|int, mixed>
List of columns that should not be displayed.
$page  : int
The current page being displayed.
$perPage  : int|null
The number of items per page.
$search  : string
The search text.
$searchColumns  : array<string|int, mixed>
List of fields that can be searched.
$searchForm  : bool|string
Determines the display of the search form.
$sort  : string|null
The column name used for sorting.
$cfg  : object
Config class instance.
$request  : Request
Server request class instance.
$sorts  : array<string|int, mixed>
The active sorting information.
$action  : string
URL for receiving actions such as delete.
$actionCallback  : string
Name of the Javascript function to call after sending data from action.
$actionConfirm  : string
Name of the JavaScript function called after clicking an action.
$border  : bool
Displays the table with borders.
$cache  : bool
Database cache.
$checkCol  : int
Column index of the checkbox.
$class  : string
Table class.
$columns  : array<string|int, mixed>
$datas  : array<string|int, mixed>
All data of the table in array format.
$debug  : bool
Displays the query on the screen.
$dragColumn  : int
Specifies the column that allows drag and drop for table reordering.
$explain  : bool
Displays the query's explain plan.
$fields  : array<string|int, mixed>
List of fields to query.
$fullWidth  : bool
Displays the table with 100% width.
$id  : string
Table ID.
$javascript  : array<string|int, mixed>
Javascript code.
$model  : QueryBuilder
Name of the Model to retrieve data from.
$onAddRow  : string
Name of the JavaScript function called when adding a new row (pmButton).
$onBeforeDelete  : string
Name of the JavaScript function called before deleting a row (pmButton).
$onChanged  : string
Name of the JavaScript function called after loading data via Ajax.
$onCreateButton  : array<string|int, mixed>
A method for preparing button rendering.
$onCreateFooter  : array<string|int, mixed>
A method to call when creating the footer.
$onCreateHeader  : array<string|int, mixed>
A method to call when creating the header.
$onDelete  : string
Name of the JavaScript function called after deleting a row (pmButton).
$onInitRow  : string
Name of the JavaScript function called to handle a new row.
$onRow  : array<string|int, mixed>
Method to handle each row's data before displaying.
$params  : array<string|int, mixed>
Array data to be sent to $url when called by Ajax.
$pmButton  : bool
Displays buttons for adding and deleting rows.
$primaryKey  : string
The primary key column name for data identification.
$responsive  : bool
Displays the table in responsive mode.
$showCaption  : bool
Displays the table caption.
$uri  : Uri
The current URI of the web page.
$url  : string
URL for reading data using Ajax.
__construct()  : mixed
Constructor.
render()  : string
Render the component.
script()  : mixed
Adds a JavaScript script to the table.
addAction()  : string|null
Adds an action element based on the provided item configuration.
addFilter()  : string
Adds a filter element based on the provided item configuration.
button()  : string
Generates HTML markup for a button element.
tbody()  : string
Generates HTML markup for the table body (<tbody>).
td()  : string
Generates HTML markup for a table cell (<td>) or header cell (<th>).
th()  : string
Generates HTML markup for a table header cell (<th>).

Properties

$actions

If specified, checkboxes and action buttons will be shown.

public array<string|int, mixed> $actions = []

Example: array('delete' => Language::get('Delete'), 'published' => Language::get('Published')) This means a select option will be shown for deleting and publishing.

$addNew

The button for adding new data.

public array<string|int, mixed> $addNew

$autoSearch

Specify the search behavior from the search box.

public bool $autoSearch = true

true (default): Automatically search based on $searchColumns. false: Manually specify the search behavior.

$buttons

Buttons to be added at the end of each row.

public array<string|int, mixed> $buttons = []

$cols

List of all columns.

public array<string|int, mixed> $cols = []

$comment

Text, such as Notes, is displayed next to the table.

public string $comment = ''

$commentClass

Note class name

public string $commentClass = 'comment'

$defaultFilters

List of main query commands for data selection.

public array<string|int, mixed> $defaultFilters = []

array('id', 1) WHERE id = 1 AND ... array('id', array(1, 2)) WHERE id IN (1, 2) AND ... array('id', '!=' , 1) WHERE id != 1 AND ...

$defaultSort

The default column name used for sorting.

public string|null $defaultSort = null

If specified, the table will be initially sorted based on this column.

$enableJavascript

Enables the usage of DataTable's JavaScript.

public bool $enableJavascript = true
  • true: Enables the usage of GTable.
  • false: Disables GTable but still allows other JavaScript to be inserted.

$entriesList

Options for the number of entries to be displayed per page.

public array<string|int, mixed> $entriesList = array(10, 20, 30, 40, 50, 100)

$filters

Data display filters.

public array<string|int, mixed> $filters = []

If this list is specified, it will display filter options above the table.

$headers

List of header names for columns.

public array<string|int, mixed> $headers = []

$hideCheckbox

Determines whether to hide the checkbox.

public bool $hideCheckbox = false

If set to true, the checkbox will always be hidden.

$hideColumns

List of columns that should not be displayed.

public array<string|int, mixed> $hideColumns = []

$page

The current page being displayed.

public int $page = 1

$perPage

The number of items per page.

public int|null $perPage = null

If specified, the table will be paginated and display options for the number of items per page.

The search text.

public string $search = ''

$searchColumns

List of fields that can be searched.

public array<string|int, mixed> $searchColumns = []

If this list is specified, it will display a search box.

$searchForm

Determines the display of the search form.

public bool|string $searchForm = 'auto'
  • 'auto' (default): Shows the search form if $searchColumns are specified.
  • true: Always shows the search form.
  • false: Doesn't show the search form.

$sort

The column name used for sorting.

public string|null $sort = null

Default is null for automatic value retrieval.

$cfg

Config class instance.

protected static object $cfg

$request

Server request class instance.

protected static Request $request

$sorts

The active sorting information.

protected array<string|int, mixed> $sorts = []

$action

URL for receiving actions such as delete.

private string $action

Format: index/[controller|model]/className/method.php

$actionCallback

Name of the Javascript function to call after sending data from action.

private string $actionCallback

Example: doFormSubmit

$actionConfirm

Name of the JavaScript function called after clicking an action.

private string $actionConfirm

For example, confirmAction(text, action, id)

$border

Displays the table with borders.

private bool $border = false

$cache

Database cache.

private bool $cache = false

$checkCol

Column index of the checkbox.

private int $checkCol = -1

-1 to hide the checkbox.

$columns

private array<string|int, mixed> $columns

$datas

All data of the table in array format.

private array<string|int, mixed> $datas

If the table does not connect to a Model, specify the data here.

$debug

Displays the query on the screen.

private bool $debug = false

$dragColumn

Specifies the column that allows drag and drop for table reordering.

private int $dragColumn = -1

$explain

Displays the query's explain plan.

private bool $explain = false

$fields

List of fields to query.

private array<string|int, mixed> $fields = []

$fullWidth

Displays the table with 100% width.

private bool $fullWidth = true

$javascript

Javascript code.

private array<string|int, mixed> $javascript = []

$onAddRow

Name of the JavaScript function called when adding a new row (pmButton).

private string $onAddRow

This function is called before $onInitRow. function(tr)

$onBeforeDelete

Name of the JavaScript function called before deleting a row (pmButton).

private string $onBeforeDelete

If the function returns true, the row will be deleted. function(tr){return true;}

$onChanged

Name of the JavaScript function called after loading data via Ajax.

private string $onChanged

function(tbody, items)

$onCreateButton

A method for preparing button rendering.

private array<string|int, mixed> $onCreateButton

If it returns false, no buttons will be created. function($btn, $attributes, $items) $btn: The button ID. $attributes: The button properties. $items: The data in the row.

array($this, methodName)

$onCreateFooter

A method to call when creating the footer.

private array<string|int, mixed> $onCreateFooter

Returns the tag within the footer. function()

array($this, methodName)

$onCreateHeader

A method to call when creating the header.

private array<string|int, mixed> $onCreateHeader

Returns the tag within the header. function()

array($this, methodName)

$onDelete

Name of the JavaScript function called after deleting a row (pmButton).

private string $onDelete

function()}

$onInitRow

Name of the JavaScript function called to handle a new row.

private string $onInitRow

function(tr, row)

$onRow

Method to handle each row's data before displaying.

private array<string|int, mixed> $onRow

function($item, $index, $prop) $item: array of data $row: index of the row (key) $prop: array of properties for the tr element, e.g., $prop[0]['id'] = xxx

array($this, methodName)

$params

Array data to be sent to $url when called by Ajax.

private array<string|int, mixed> $params = []

$pmButton

Displays buttons for adding and deleting rows.

private bool $pmButton = false

$primaryKey

The primary key column name for data identification.

private string $primaryKey = 'id'

Used to read the ID of each row.

$responsive

Displays the table in responsive mode.

private bool $responsive = false

$showCaption

Displays the table caption.

private bool $showCaption = true

$url

URL for reading data using Ajax.

private string $url = null

Returns JSON data based on columns.

Methods

__construct()

Constructor.

public __construct(array<string|int, mixed> $param) : mixed
Parameters
$param : array<string|int, mixed>

The parameters to initialize the object.

Return values
mixed

render()

Render the component.

public render() : string

This function is responsible for rendering the component. It generates the necessary HTML code based on the provided data.

Return values
string

script()

Adds a JavaScript script to the table.

public script(string $script) : mixed
Parameters
$script : string

The JavaScript script to add.

Return values
mixed

addAction()

Adds an action element based on the provided item configuration.

private addAction(array<string|int, mixed> $item) : string|null
Parameters
$item : array<string|int, mixed>

The item configuration for the action element.

Return values
string|null

The generated HTML for the action element, or null if no action is defined.

addFilter()

Adds a filter element based on the provided item configuration.

private addFilter(array<string|int, mixed> $item) : string
Parameters
$item : array<string|int, mixed>

The item configuration for the filter element.

Return values
string

The generated HTML for the filter element.

button()

Generates HTML markup for a button element.

private button(string $btn, array<string|int, mixed> $properties, array<string|int, mixed> $items) : string
Parameters
$btn : string

The button identifier.

$properties : array<string|int, mixed>

The properties of the button.

$items : array<string|int, mixed>

The items associated with the button.

Return values
string

The generated HTML for the button element.

tbody()

Generates HTML markup for the table body (<tbody>).

private tbody(int $start, int $end) : string
Parameters
$start : int

The start index of the rows to be included in the tbody.

$end : int

The end index of the rows to be included in the tbody.

Return values
string

The generated HTML for the table body.

td()

Generates HTML markup for a table cell (<td>) or header cell (<th>).

private td(string $id, int $i, array<string|int, mixed> $properties, string $text, string $th) : string
Parameters
$id : string

The cell ID.

$i : int

The cell index.

$properties : array<string|int, mixed>

The properties of the cell.

$text : string

The cell content.

$th : string

The content of the corresponding table header cell.

Return values
string

The generated HTML for the table cell.

th()

Generates HTML markup for a table header cell (<th>).

private th(int $i, string $column, array<string|int, mixed> $properties) : string
Parameters
$i : int

The column index.

$column : string

The column name or identifier.

$properties : array<string|int, mixed>

The properties of the table header cell.

Return values
string

The generated HTML for the table header cell.

Search results