class GridFieldEditableColumns extends GridFieldDataColumns implements GridField_HTMLProvider, GridField_SaveHandler, GridField_URLHandler (View source)

Allows inline editing of grid field records without having to load a separate edit interface.

The form fields used can be configured by setting the value in setDisplayFields() to one of the following forms:

  • A Closure which returns the field instance.
  • An array with a callback key pointing to a function which returns the field.
  • An array with a field key->response specifying the field class to use.

Traits

A class that can be instantiated or replaced via DI

Constants

POST_KEY

Properties

public array $fieldCasting from  GridFieldDataColumns
public array $fieldFormatting from  GridFieldDataColumns
protected array $displayFields

This is the columns that will be visible

from  GridFieldDataColumns
protected Form[] $forms

Methods

public static 
create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

public static 
singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

public
augmentColumns(GridField $gridField, array $columns)

Modify the list of columns displayed in the table.

public
array
getColumnsHandled(GridField $gridField)

Names of all columns which are affected by this component.

public
$this
setDisplayFields(array $fields)

Override the default behaviour of showing the models summaryFields with these fields instead Example: array( 'Name' => 'Members name', 'Email' => 'Email address')

public
array
getDisplayFields(GridField $gridField)

Get the DisplayFields

public
$this
setFieldCasting(array $casting)

Specify castings with fieldname as the key, and the desired casting as value.

public
array
getFieldCasting()

No description

public
$this
setFieldFormatting(array $formatting)

Specify custom formatting for fields, e.g. to render a link instead of pure text.

public
array
getFieldFormatting()

No description

public
string
getColumnContent($grid, ViewableData $record, $col)

HTML for the column, content of the element.

public
array
getColumnAttributes(GridField $gridField, ViewableData $record, string $columnName)

Attributes for the element containing the content returned by getColumnContent().

public
array
getColumnMetadata(GridField $gridField, string $column)

Additional metadata about the column which can be used by other components, e.g. to set a title for a search column header.

protected
string|null
getValueFromRelation(ViewableData $record, string $columnName) deprecated

Translate a Object.RelationName.ColumnName $columnName into the value that ColumnName returns

protected
string
castValue(GridField $gridField, string $fieldName, string $value)

Casts a field to a string which is safe to insert into HTML

protected
string
formatValue(GridField $gridField, ViewableData $item, string $fieldName, string $value)

No description

protected
string
escapeValue(GridField $gridField, string $value)

Remove values from a value using FieldEscape setter

public
array
getHTMLFragments($grid)

Returns a map where the keys are fragment names and the values are pieces of HTML to add to these fragments.

public
handleSave(GridField $grid, DataObjectInterface $record)

Called when a grid field is saved - i.e. the form is submitted.

public
handleForm(GridField $grid, HTTPRequest $request)

No description

public
array
getURLHandlers($grid)

Return URLs to be handled by this grid field, in an array the same form as $url_handlers.

public
getFields(GridField $grid, DataObjectInterface $record)

Gets the field list for a record.

public
getForm(GridField $grid, DataObjectInterface $record)

Gets the form instance for a record.

protected
getFieldName($name, GridField $grid, DataObjectInterface $record)

No description

Details

static Injectable create(mixed ...$args)

An implementation of the factory method, allows you to create an instance of a class

This method will defer class substitution to the Injector API, which can be customised via the Config API to declare substitution classes.

This can be called in one of two ways - either calling via the class directly, or calling on Object and passing the class name as the first parameter. The following are equivalent: $list = DataList::create(SiteTree::class); $list = SiteTree::get();

Parameters

mixed ...$args

Return Value

Injectable

static Injectable singleton(string $class = null)

Creates a class instance by the "singleton" design pattern.

It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling).

Parameters

string $class

Optional classname to create, if the called class should not be used

Return Value

Injectable

The singleton instance

augmentColumns(GridField $gridField, array $columns)

Modify the list of columns displayed in the table.

See GridFieldDataColumns->getDisplayFields()} and {@link GridFieldDataColumns.

Parameters

GridField $gridField
array $columns

List reference of all column names.

array getColumnsHandled(GridField $gridField)

Names of all columns which are affected by this component.

Parameters

GridField $gridField

Return Value

array

$this setDisplayFields(array $fields)

Override the default behaviour of showing the models summaryFields with these fields instead Example: array( 'Name' => 'Members name', 'Email' => 'Email address')

Parameters

array $fields

Return Value

$this

array getDisplayFields(GridField $gridField)

Get the DisplayFields

Parameters

GridField $gridField

Return Value

array

See also

GridFieldDataColumns::setDisplayFields

$this setFieldCasting(array $casting)

Specify castings with fieldname as the key, and the desired casting as value.

Example: array("MyCustomDate"=>"Date","MyShortText"=>"Text->FirstSentence")

Parameters

array $casting

Return Value

$this

array getFieldCasting()

No description

Return Value

array

$this setFieldFormatting(array $formatting)

Specify custom formatting for fields, e.g. to render a link instead of pure text.

Caution: Make sure to escape special php-characters like in a normal php-statement. Example: "myFieldName" => '<a href=\"custom-admin/$ID\">$ID'.

Alternatively, pass a anonymous function, which takes two parameters: The value and the original list item.

Formatting is applied after field casting, so if you're modifying the string to include further data through custom formatting, ensure it's correctly escaped.

Parameters

array $formatting

Return Value

$this

array getFieldFormatting()

No description

Return Value

array

string getColumnContent($grid, ViewableData $record, $col)

HTML for the column, content of the element.

Parameters

$grid
ViewableData $record
  • Record displayed in this row
$col

Return Value

string
  • HTML for the column. Return NULL to skip.

array getColumnAttributes(GridField $gridField, ViewableData $record, string $columnName)

Attributes for the element containing the content returned by getColumnContent().

Parameters

GridField $gridField
ViewableData $record

displayed in this row

string $columnName

Return Value

array

array getColumnMetadata(GridField $gridField, string $column)

Additional metadata about the column which can be used by other components, e.g. to set a title for a search column header.

Parameters

GridField $gridField
string $column

Return Value

array
  • Map of arbitrary metadata identifiers to their values.

protected string|null getValueFromRelation(ViewableData $record, string $columnName) deprecated

deprecated 5.4.0 Will be removed without equivalent functionality to replace it.

Translate a Object.RelationName.ColumnName $columnName into the value that ColumnName returns

Parameters

ViewableData $record
string $columnName

Return Value

string|null
  • returns null if it could not found a value

protected string castValue(GridField $gridField, string $fieldName, string $value)

Casts a field to a string which is safe to insert into HTML

Parameters

GridField $gridField
string $fieldName
string $value

Return Value

string

protected string formatValue(GridField $gridField, ViewableData $item, string $fieldName, string $value)

No description

Parameters

GridField $gridField
ViewableData $item
string $fieldName
string $value

Return Value

string

protected string escapeValue(GridField $gridField, string $value)

Remove values from a value using FieldEscape setter

Parameters

GridField $gridField
string $value

Return Value

string

array getHTMLFragments($grid)

Returns a map where the keys are fragment names and the values are pieces of HTML to add to these fragments.

Here are 4 built-in fragments: 'header', 'footer', 'before', and 'after', but components may also specify fragments of their own.

To specify a new fragment, specify a new fragment by including the text "$DefineFragment(fragmentname)" in the HTML that you return.

Fragment names should only contain alphanumerics, -, and _.

If you attempt to return HTML for a fragment that doesn't exist, an exception will be thrown when the GridField is rendered.

Parameters

$grid

Return Value

array

handleSave(GridField $grid, DataObjectInterface $record)

Called when a grid field is saved - i.e. the form is submitted.

Parameters

GridField $grid
DataObjectInterface $record

Form handleForm(GridField $grid, HTTPRequest $request)

No description

Parameters

GridField $grid
HTTPRequest $request

Return Value

Form

Exceptions

HTTPResponse_Exception

array getURLHandlers($grid)

Return URLs to be handled by this grid field, in an array the same form as $url_handlers.

Handler methods will be called on the component, rather than the GridField.

Parameters

$grid

Return Value

array

FieldList getFields(GridField $grid, DataObjectInterface $record)

Gets the field list for a record.

Parameters

GridField $grid
DataObjectInterface $record

Return Value

FieldList

Exceptions

Exception

Form getForm(GridField $grid, DataObjectInterface $record)

Gets the form instance for a record.

Parameters

GridField $grid
DataObjectInterface $record

Return Value

Form

protected getFieldName($name, GridField $grid, DataObjectInterface $record)

No description

Parameters

$name
GridField $grid
DataObjectInterface $record