Class Options
The Options class provides a convenient method of specifying where Editor
should get the list of options for a select
, radio
or checkbox
field.
This is normally from a table that is left joined to the main table being
edited, and a list of the values available from the joined table is shown to
the end user to let them select from.
Options
instances are used with the Field::options method.
-
DataTables\Ext
-
DataTables\Editor\Options
Namespace: DataTables\
Editor
Example:
Get a list of options from the sites
table
Field::inst( 'users.site' )
->options( Options::inst()
->table( 'sites' )
->value( 'id' )
->label( 'name' )
)
Example:
Get a list of options with custom ordering
Field::inst( 'users.site' )
->options( Options::inst()
->table( 'sites' )
->value( 'id' )
->label( 'name' )
->order( 'name DESC' )
)
Example:
Get a list of options showing the id and name in the label
Field::inst( 'users.site' )
->options( Options::inst()
->table( 'sites' )
->value( 'id' )
->label( [ 'name', 'id' ] )
->render( function ( $row ) {
return $row['name'].' ('.$row['id'].')';
} )
)
Located at Editor/Options.php
Methods summary
public
DataTables\Editor\Options
|
#
add( string $label, string|null $value = null )
Add extra options to the list, in addition to any obtained from the database
Add extra options to the list, in addition to any obtained from the database
Parameters
- $label
- The label to use for the option
- $value
- Value for the option. If not given, the label will be used
Returns
|
public
DataTables\Editor\Options |string[]
|
#
label( null|string|string[] $_ = null )
Get / set the column(s) to use as the label value of the options
Get / set the column(s) to use as the label value of the options
Parameters
- $_
null to get the current value, string or
array to get.
Returns
|
public
DataTables\Editor\Options |string[]
|
#
limit( null|number $_ = null )
Get / set the LIMIT clause to limit the number of records returned.
Get / set the LIMIT clause to limit the number of records returned.
Parameters
- $_
- Number of rows to limit the result to
Returns
|
public
DataTables\Editor\Options |string
|
#
order( null|string $_ = null )
Get / set the ORDER BY clause to use in the SQL. If this option is not
provided the ordering will be based on the rendered output, either
numerically or alphabetically based on the data returned by the renderer.
Get / set the ORDER BY clause to use in the SQL. If this option is not
provided the ordering will be based on the rendered output, either
numerically or alphabetically based on the data returned by the renderer.
Parameters
- $_
- String to set, null to get current value
Returns
|
public
DataTables\Editor\Options |callable
|
#
render( null|callable $_ = null )
Get / set the label renderer. The renderer can be used to combine
multiple database columns into a single string that is shown as the label
to the end user in the list of options.
Get / set the label renderer. The renderer can be used to combine
multiple database columns into a single string that is shown as the label
to the end user in the list of options.
Parameters
- $_
- Function to set, null to get current value
Returns
|
public
DataTables\Editor\Options |string
|
#
table( null|string $_ = null )
Get / set the database table from which to gather the options for the
list.
Get / set the database table from which to gather the options for the
list.
Parameters
- $_
- String to set, null to get current value
Returns
|
public
DataTables\Editor\Options |string
|
#
value( null|string $_ = null )
Get / set the column name to use for the value in the options list. This
would normally be the primary key for the table.
Get / set the column name to use for the value in the options list. This
would normally be the primary key for the table.
Parameters
- $_
- String to set, null to get current value
Returns
|
public
DataTables\Editor\Options |callable
|
#
where( null|callable $_ = null )
Get / set the method to use for a WHERE condition if it is to be
applied to the query to get the options.
Get / set the method to use for a WHERE condition if it is to be
applied to the query to get the options.
Parameters
- $_
- Function to set, null to get current value
Returns
|