set()
Set the value of one or more fields.
Please note - this property requires the Editor extension for DataTables.
Description
It is often useful to be able to programmatically set the value of a field, or multiple fields. This method provides that ability.
When used while multi-row editing, for each individual field specified in the fieldNames parameter, this method will set the field value for all items being edited to be the same value (that passed in). If you need the ability to set item values individually, please refer to the multiSet() or field().multiSet() methods.
In addition to this method, Editor provides a number of other methods that can be used to get and set field values - each with their own speciality. Please refer to the Related selection below for links to these methods.
Type
set( fieldNames [, value ] )
Set the value for one or more fields.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | fieldNames | No | |
The field name to set the value of. If given as an object each property name is the name of the field to set and the property value, the value to set for the field. | |||
| 2 | value |
| Yes |
The value to set the field to. The format of the value will depend upon the field type. Not required if the first parameter is given as an object. | |||
Returns:
DataTable.Editor: Editor instance
Examples
Set the values of a few fields before then automatically submitting the form:
editor
.create(false)
.set('name', 'Test user')
.set('access', 'Read only')
.submit();As above, but setting multiple fields at the same time using an object:
editor
.create(false)
.set({
name: 'Test user',
access: 'Read only'
})
.submit();Related
The following options are directly related and may also be useful in your application development.