field().multiGet()
Get the values for a field (multi-row editing aware).
Please note - this property requires the Editor extension for DataTables.
Description
This method is specifically designed for Editor's multi-row editing feature. It provides the ability to get the values that a field has for one or more items that are being edited.
To illustrate, consider an Editor instance that has been set up to edit two rows in a DataTable which have the row id's of row_27 and row_31. If there is a field called first_name we might have:
editor.field('first_name').multiGet();
// Result:
// {
// "row_27": "Allan",
// "row_31": "Bob"
// }
Note how this single field can have multiple values assigned to it for each item being edited. Equally they could both be the same value is the user has edited the value using the Editor UI. The field().isMultiValue() method can be used to determine if a field contains different values for the items being edited or not.
We can also get the value for a single item by passing a parameter into the method:
editor.field('first_name').multiGet( 'row_27' );
// Result:
// "Allan"
The field().multiSet() method provides the setter version of this method.
Note that there is no field().multiVal() method like there is for single value editing, as such a method's arguments could potentially be ambiguous. Thus the distinction between field().multiGet() and field().multiSet().
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
field(…).multiGet( [ id ] )
Get the current value(s) of a field.
Parameters:
| Name | Type | Optional | |
|---|---|---|---|
| 1 | id | Yes | |
Row id of a specific item being edited to get the field value for that item only. This can be left as undefined to get an object that contains the values for all items being edited. | |||
Returns:
object or Any:
If the passed in parameter is undefined an object is returned with the value for all items being edited, where the parameter keys in the object are the item ids.
If an id is given, the field's value for the item with that id is returned.
Example
Get the value for a specific editing item, and then use it to set the value of all editing items:
var field = editor.field('first_name');
if (field.isMultiValue()) {
var val = field.multiGet('row_27');
field.val(val);
}Related
The following options are directly related and may also be useful in your application development.