get()
Get 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 get the value of a field, or multiple fields, for example in client-side validation, or data manipulation. This method provides that ability.
When used with multi-row editing, the values returned for each field are governed by the following rules:
- If all items being edited have the same value for the field, that value is returned
- If the items being edited have different values for the field,
undefinedis returned.multiGet()orfield().multiGet()should be used to access individual values if this is the case.
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
get( fieldName )
Get the value of one or more fields.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | fieldName | No | |
The field name(s) to obtain the values of. Multiple fields can be used by passing the value in as an array of field names. | |||
Returns:
Any or object:
The value of the field if a string was used as the fieldName parameter, or an object, with the keys set to the field names and the value to the corresponding field's value, if fieldName was given as an array.
Examples
Client-side validation using preSubmit:
editor.on('preSubmit', function () {
if (this.get('first_name') === '') {
this.error('first_name', 'This field is required');
return false;
}
return true;
});Check a value from a row being edited and submit immediately if certain data is found.:
$('#myTable tbody').on('click', 'tr', function () {
editor.edit(this, false);
if (editor.get('access') === 'all') {
editor.set('admin', 1).submit();
}
});Related
The following options are directly related and may also be useful in your application development.