Menu

## DataTable extends KBase
in package

DataTable.php : 20

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

DataTable.php : 131

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

DataTable.php : 385

The button for adding new data.

`public array<string|int, mixed> $addNew`

#### $autoSearch

DataTable.php : 243

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

DataTable.php : 297

Buttons to be added at the end of each row.

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

#### $cols

DataTable.php : 222

List of all columns.

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

#### $comment

DataTable.php : 391

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

`public string $comment = ''`

#### $commentClass

DataTable.php : 397

Note class name

`public string $commentClass = 'comment'`

#### $defaultFilters

DataTable.php : 203

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

DataTable.php : 285

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

DataTable.php : 351

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

DataTable.php : 363

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

DataTable.php : 210

Data display filters.

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

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

#### $headers

DataTable.php : 228

List of header names for columns.

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

#### $hideCheckbox

DataTable.php : 85

Determines whether to hide the checkbox.

`public bool $hideCheckbox = false`

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

#### $hideColumns

DataTable.php : 216

List of columns that should not be displayed.

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

#### $page

DataTable.php : 271

The current page being displayed.

`public int $page = 1`

#### $perPage

DataTable.php : 265

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.

#### $search

DataTable.php : 258

The search text.

`public string $search = ''`

#### $searchColumns

DataTable.php : 235

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

DataTable.php : 252

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

DataTable.php : 278

The column name used for sorting.

`public string|null $sort = null`

Default is null for automatic value retrieval.

#### $cfg

KBase.php : 26

Config class instance.

`protected static object $cfg`

#### $request

KBase.php : 33

Server request class instance.

`protected static Request $request`

#### $sorts

DataTable.php : 291

The active sorting information.

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

#### $action

DataTable.php : 123

URL for receiving actions such as delete.

`private string $action`

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

#### $actionCallback

DataTable.php : 138

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

`private string $actionCallback`

Example: doFormSubmit

#### $actionConfirm

DataTable.php : 146

Name of the JavaScript function called after clicking an action.

`private string $actionConfirm`

For example, confirmAction(text, action, id)

#### $border

DataTable.php : 97

Displays the table with borders.

`private bool $border = false`

#### $cache

DataTable.php : 65

Database cache.

`private bool $cache = false`

#### $checkCol

DataTable.php : 78

Column index of the checkbox.

`private int $checkCol = -1`

-1 to hide the checkbox.

#### $class

DataTable.php : 33

Table class.

`private string $class`

#### $columns

DataTable.php : 379
`private array<string|int, mixed> $columns`

#### $datas

DataTable.php : 46

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

DataTable.php : 369

Displays the query on the screen.

`private bool $debug = false`

#### $dragColumn

DataTable.php : 330

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

`private int $dragColumn = -1`

#### $explain

DataTable.php : 375

Displays the query's explain plan.

`private bool $explain = false`

#### $fields

DataTable.php : 71

List of fields to query.

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

#### $fullWidth

DataTable.php : 91

Displays the table with 100% width.

`private bool $fullWidth = true`

#### $id

DataTable.php : 27

Table ID.

`private string $id`

#### $javascript

DataTable.php : 343

Javascript code.

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

#### $model

DataTable.php : 39

Name of the Model to retrieve data from.

`private QueryBuilder $model`

#### $onAddRow

DataTable.php : 180

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

`private string $onAddRow`

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

#### $onBeforeDelete

DataTable.php : 165

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

DataTable.php : 194

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

`private string $onChanged`

function(tbody, items)

#### $onCreateButton

DataTable.php : 308

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

DataTable.php : 324

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

DataTable.php : 316

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

DataTable.php : 172

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

`private string $onDelete`

function()}

#### $onInitRow

DataTable.php : 187

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

`private string $onInitRow`

function(tr, row)

#### $onRow

DataTable.php : 157

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

DataTable.php : 59

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

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

#### $pmButton

DataTable.php : 103

Displays buttons for adding and deleting rows.

`private bool $pmButton = false`

#### $primaryKey

DataTable.php : 337

The primary key column name for data identification.

`private string $primaryKey = 'id'`

Used to read the ID of each row.

#### $responsive

DataTable.php : 109

Displays the table in responsive mode.

`private bool $responsive = false`

#### $showCaption

DataTable.php : 115

Displays the table caption.

`private bool $showCaption = true`

#### $uri

DataTable.php : 357

The current URI of the web page.

`private Uri $uri`

#### $url

DataTable.php : 53

URL for reading data using Ajax.

`private string $url = null`

Returns JSON data based on columns.

### Methods

#### __construct()

DataTable.php : 404

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()

DataTable.php : 537

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()

DataTable.php : 524

Adds a JavaScript script to the table.

`public script(string $script) : mixed`

##### Parameters

$script : string

  The JavaScript script to add.

##### Return values

mixed —

#### addAction()

DataTable.php : 1253

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()

DataTable.php : 1331

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()

DataTable.php : 1160

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()

DataTable.php : 969

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()

DataTable.php : 1130

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()

DataTable.php : 1099

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