Version: current

# Class TableField

TableField behaves in the same manner as TableListField, however allows the addition of fields and editing of attributes specified, and filtering results.

Caution: If you insert DropdownFields in the fieldTypes-array, make sure they have an empty first option. Otherwise the saving can't determine if a new row should really be saved.

Caution: TableField relies on {@FormResponse} to reload the field after it is saved. A TableField-instance should never be saved twice without reloading, because otherwise it can't determine if a field is new (=create) or existing (=update), and will produce duplicates.

  Object
  ViewableData implements IteratorAggregate
  RequestHandler
  FormField
  TableListField
  TableField

Package: forms\fields-relational
Param: $name string The fieldname
Param: $sourceClass string The source class of this field
Param: $fieldList array An array of field headings of Fieldname => Heading Text (eg. heading1)
Param: $fieldTypes array An array of field types of fieldname => fieldType (eg. formfield). Do not use for extra data/hiddenfields.
Param: $filterField string The field to filter by. Give the filter value in $sourceFilter. The value will automatically be set on new records.
Param: $sourceFilter string If $filterField has a value, then this is the value to filter by. Otherwise, it is a SQL filter expression.
Param: $editExisting boolean (Note: Has to stay on this position for legacy reasons)
Param: $sourceSort string
Param: $sourceJoin string
Located at sapphire/forms/TableField.php

## Methods summary

`public` | # `__construct( `FormField::$name` $name, `FormField::$title` $sourceClass, `FormField::$value` $fieldList = null, `FormField::$form` $fieldTypes, maxLength $filterField = null, mixed $sourceFilter = null, mixed $editExisting = true, mixed $sourceSort = null, mixed $sourceJoin = null )` Create a new field. Create a new field. #### Parameters $name name The internal field name, passed to forms. $sourceClass title The field label. $fieldList value The value of the field. $fieldTypes form Reference to the container form $filterField maxLength The Maximum length of the attribute $sourceFilter $editExisting $sourceSort $sourceJoin #### Overrides `TableListField::__construct`
`public `DataObjectSet`` | # `Headings( )` Displays the headings on the template Displays the headings on the template #### Returns ``DataObjectSet`` DataObjectSet #### Overrides `TableListField::Headings`
`public integer` | # `ItemCount( )` Calculates the number of columns needed for colspans used in template Calculates the number of columns needed for colspans used in template #### Returns `integer` int
`public `DataObjectSet`` | # `Items( )` Displays the items from `TableListField::sourceItems()` using the encapsulation object. If the field value has been set as an array (e.g. after a failed validation), it generates the rows from array data instead. Used in the formfield template to iterate over each row. Displays the items from `TableListField::sourceItems()` using the encapsulation object. If the field value has been set as an array (e.g. after a failed validation), it generates the rows from array data instead. Used in the formfield template to iterate over each row. #### Returns ``DataObjectSet`` Collection of `TableField_Item` #### Overrides `TableListField::Items`
`protected `TableField_Item`` | # `generateTableFieldItem( `DataObject` $dataObj )` Generates a new `TableField` instance by loading a fieldset for this row into a temporary form. Generates a new `TableField` instance by loading a fieldset for this row into a temporary form. #### Parameters $dataObj DataObject $dataObj #### Returns ``TableField_Item`` TableField_Item
`public array` | # `FieldList( )` #### Returns `array` array #### Overrides `TableListField::FieldList`
`public` | # `saveInto( `DataObject` $record )` Saves the Dataobjects contained in the field Saves the Dataobjects contained in the field #### Overrides `FormField::saveInto`
`public `FieldSet`` | # `FieldSetForRow( )` Get all `FormField` instances necessary for a single row, respecting the casting set in `TableField::$fieldTypes`. Doesn't populate with any data. Optionally performs a readonly transformation if $IsReadonly is set, or the current user doesn't have edit permissions. Get all `FormField` instances necessary for a single row, respecting the casting set in `TableField::$fieldTypes`. Doesn't populate with any data. Optionally performs a readonly transformation if $IsReadonly is set, or the current user doesn't have edit permissions. #### Returns ``FieldSet`` FieldSet
`public` | # `performReadonlyTransformation( )` Returns a readonly version of this field Returns a readonly version of this field #### Overrides `TableListField::performReadonlyTransformation`
`public` | # `performDisabledTransformation( )` Return a disabled version of this field Return a disabled version of this field #### Overrides `FormField::performDisabledTransformation`
`public mixed` | # `getField( string $fieldName, mixed $combinedFieldName = null )` Needed for Form->callfieldmethod. Needed for Form->callfieldmethod. #### Parameters $fieldName string $field $combinedFieldName #### Returns `mixed` mixed #### Overrides `ViewableData::getField`
`public array` | # `saveData( `DataObjectSet` $dataObjects, boolean $existingValues = true )` Called on save, it creates the appropriate objects and writes them to the database. Called on save, it creates the appropriate objects and writes them to the database. #### Parameters $dataObjects DataObjectSet $dataObjects $existingValues boolean $existingValues If set to TRUE, it tries to find existing objects based on the database IDs passed as array keys in $dataObjects parameter. If set to FALSE, it will always create new object (default: TRUE) #### Returns `array` Array of saved object IDs in the key, and the status ("Updated") in the value
`public array` | # `sortData( array $data, integer $recordID = null )` Organises the data in the appropriate manner for saving Organises the data in the appropriate manner for saving #### Parameters $data array $data $recordID int $recordID #### Returns `array` Collection of maps suitable to construct DataObjects
`public` | # `setExtraData( mixed $extraData )` #### Parameters $extraData $extraData array
`public array` | # `getExtraData( )` #### Returns `array` array
`public` | # `FieldHolder( )` Sets the template to be rendered with Sets the template to be rendered with #### Overrides `TableListField::FieldHolder`
`public `Int`` | # `sourceID( )` #### Returns ``Int`` Int #### Overrides `TableListField::sourceID`
`public` | # `setTransformationConditions( mixed $conditions )`
`public` | # `jsValidation( )` javascript handler Functions for each field type by default formfield doesnt have a validation function javascript handler Functions for each field type by default formfield doesnt have a validation function #### Overrides `FormField::jsValidation`
`public` | # `php( mixed $data )`
`public` | # `validate( mixed $validator )` Validation Functions for each field type by default formfield doesnt have a validation function Validation Functions for each field type by default formfield doesnt have a validation function #### Overrides `FormField::validate`
`public` | # `setRequiredFields( mixed $fields )`
`public` | # `setRelationAutoSetting( boolean $value )` #### Parameters $value boolean $value
`public boolean` | # `getRelationAutoSetting( )` #### Returns `boolean` boolean

### Methods inherited from TableListField

`Actions()`, `BaseLink()`, `Can()`, `CurrentLink()`, `ExportLink()`, `FirstItem()`, `FirstLink()`, `GroupedItems()`, `HasGroupedItems()`, `HasSummary()`, `LastItem()`, `LastLink()`, `ListStart()`, `Name()`, `NamePlural()`, `NameSingular()`, `NextLink()`, `PageSize()`, `PrevLink()`, `PrintLink()`, `ShowPagination()`, `SummaryFields()`, `SummaryTitle()`, `Title()`, `TotalCount()`, `Utility()`, `addSummary()`, `ajax_refresh()`, `colFunction_avg()`, `colFunction_sum()`, `delete()`, `disableSorting()`, `export()`, `filterString()`, `generateExportFileData()`, `getCastedValue()`, `getCsvQuery()`, `getCsvSeparator()`, `getExtraLinkParams()`, `getPermissions()`, `getQuery()`, `handleItem()`, `index()`, `isFieldSortable()`, `permissions_for_object()`, `printall()`, `removeCsvHeader()`, `removeSummary()`, `setCSVFieldFormatting()`, `setClick_AjaxLoad()`, `setClick_PopupLoad()`, `setCsvSeparator()`, `setCustomCsvQuery()`, `setCustomQuery()`, `setCustomSourceItems()`, `setExtraLinkParams()`, `setFieldCasting()`, `setFieldFormatting()`, `setFieldList()`, `setFieldListCsv()`, `setHighlightConditions()`, `setPageSize()`, `setPermissions()`, `setShowPagination()`, `setTemplate()`, `sourceClass()`, `sourceFilter()`, `sourceItems()`

### Methods inherited from FormField

`Field()`, `LeftTitle()`, `Link()`, `Message()`, `MessageType()`, `Required()`, `RightTitle()`, `SmallFieldHolder()`, `Type()`, `Value()`, `addExtraAttribute()`, `addExtraClass()`, `allowHTML5()`, `allow_html5()`, `attrName()`, `attrTitle()`, `attrValue()`, `createTag()`, `dataValue()`, `debug()`, `describe()`, `extraClass()`, `fieldHolderTemplates()`, `fieldTemplates()`, `forTemplate()`, `getCustomValidationMessage()`, `getExtraClasses()`, `getForm()`, `getHTML5Attribute()`, `getTabIndex()`, `getTabIndexHTML()`, `hasClass()`, `hasData()`, `id()`, `isComposite()`, `isDisabled()`, `isReadonly()`, `name_to_label()`, `removeExtraAttribute()`, `removeExtraClass()`, `rootFieldSet()`, `securityTokenEnabled()`, `setAutocomplete()`, `setContainerFieldSet()`, `setCustomValidationMessage()`, `setDisabled()`, `setError()`, `setFieldHolderTemplate()`, `setForm()`, `setHTML5Attribute()`, `setLeftTitle()`, `setName()`, `setReadonly()`, `setRightTitle()`, `setSmallFieldHolderTemplate()`, `setTabIndex()`, `setTitle()`, `setValue()`, `smallFieldHolderTemplates()`, `transform()`, `useHTML5()`, `use_html5()`

### Methods inherited from RequestHandler

`allowedActions()`, `checkAccessAction()`, `getRequest()`, `handleRequest()`, `hasAction()`, `httpError()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `CurrentPage()`, `Debug()`, `Even()`, `EvenOdd()`, `First()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Last()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `TotalItems()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `defineMethods()`, `escapeTypeForField()`, `getIterator()`, `getSecurityID()`, `getXMLValues()`, `hasField()`, `hasValue()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`, `setField()`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `exists()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected mixed` | $sourceClass | #
`protected mixed` | $sourceFilter | #
`protected mixed` | $fieldList | #
`protected mixed` | $filterField | # A "Field = Value" filter can be specified by setting $this->filterField and $this->filterValue. This has the advantage of auto-populating new records A "Field = Value" filter can be specified by setting $this->filterField and $this->filterValue. This has the advantage of auto-populating new records
`protected mixed` | $filterValue | # A "Field = Value" filter can be specified by setting $this->filterField and $this->filterValue. This has the advantage of auto-populating new records A "Field = Value" filter can be specified by setting $this->filterField and $this->filterValue. This has the advantage of auto-populating new records
`protected mixed` | $fieldTypes | # FieldSet Caution: Use {@setExtraData()} instead of manually adding HiddenFields if you want to preset relations or other default data. FieldSet Caution: Use {@setExtraData()} instead of manually adding HiddenFields if you want to preset relations or other default data.
`protected mixed` | $sourceSort | #
`protected mixed` | $sourceJoin | #
`protected string` | $template | # string Template-Overrides string Template-Overrides
`protected mixed` | $extraData | # array Any extra data that need to be included, e.g. to retain has-many relations. Format: array('FieldName' => 'Value') array Any extra data that need to be included, e.g. to retain has-many relations. Format: array('FieldName' => 'Value')
`protected mixed` | $tempForm | #
`protected array` | $permissions | # Influence output without having to subclass the template. Influence output without having to subclass the template.
`public array` | $transformationConditions | #
`protected mixed` | $requiredFields | # array Required fields as a numerical array. Please use an instance of Validator on the including form. array Required fields as a numerical array. Please use an instance of Validator on the including form.
`public boolean` | $showAddRow | # Shows a row of empty fields for adding a new record (turned on by default). Please use `TableField::$permissions` to control if the "add"-functionality incl. button is shown at all. Shows a row of empty fields for adding a new record (turned on by default). Please use `TableField::$permissions` to control if the "add"-functionality incl. button is shown at all. #### Param boolean $showAddRow
`protected boolean` | $relationAutoSetting | # Automatically detect a has-one relationship in the popup (=child-class) and save the relation ID. Automatically detect a has-one relationship in the popup (=child-class) and save the relation ID.

### Properties inherited from TableListField

`$IsReadOnly`, `$Markable`, `$MarkableTitle`, `$__cachedQuery`, `$actions`, `$cachedSourceItems`, `$clickAction`, `$csvFieldEscape`, `$csvFieldFormatting`, `$csvHasHeader`, `$csvSeparator`, `$customCsvQuery`, `$customQuery`, `$customSourceItems`, `$defaultAction`, `$disableSorting`, `$exportButtonLabel`, `$extraLinkParams`, `$fieldCasting`, `$fieldFormatting`, `$fieldListCsv`, `$groupByField`, `$highlightConditions`, `$itemClass`, `$methodName`, `$pageSize`, `$paginationBaseLink`, `$readOnly`, `$showPagination`, `$summaryFieldList`, `$summaryTitle`, `$totalCount`, `$url_handlers`

### Properties inherited from FormField

`$autocomplete`, `$containerFieldSet`, `$customValidationMessage`, `$description`, `$disabled`, `$dontEscape`, `$extraAttributes`, `$extraClass`, `$extraClasses`, `$fieldHTML5`, `$fieldHolderTemplate`, `$form`, `$html5Attributes`, `$leftTitle`, `$message`, `$messageType`, `$name`, `$possible_autocomplete_values`, `$readonly`, `$rightTitle`, `$smallFieldHolderTemplate`, `$tabIndex`, `$title`, `$use_html5`, `$value`

### Properties inherited from RequestHandler

`$allowed_actions`, `$brokenOnConstruct`, `$request`

### Properties inherited from ViewableData

`$casting`, `$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -