field().multiSet()

Since: Editor 1.5

Set the values for a field (multi-row editing aware).
Please note - this property requires the Editor extension for DataTables.

Description

Multi-row editing is a powerful feature in Editor, particularly if you have the ability to programmatically set individual values for items being edited. This method provides exactly that ability and thus makes possible features such as an Excel like AutoFill, row reordering and other advanced features.

To illustrate this method, 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 initially use field().multiGet() to find the following:

editor.field('first_name').multiGet();

// Result:
//  {
//      "row_27": "Allan",
//      "row_31": "Bob"
//  }

The individual values can be modified thus:

editor.field('first_name').multiSet( 'row_27', 'Fred' );

editor.field('first_name').multiGet();

// Result:
//  {
//      "row_27": "Fred",
//      "row_31": "Bob"
//  }

Note how this single field can have multiple values assigned to it for each item being edited. The values can match or be different as in the case above. 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 set the value for all items being edited by not passing in an id parameter (this is the equivalent of using the field().val() or field().set() methods):

editor.field('first_name').multiSet( 'Fiona' );

editor.field('first_name').multiGet();

// Result:
//  {
//      "row_27": "Fiona",
//      "row_31": "Fiona"
//  }

The field().multiGet() method provides the getter version of this method. Additionally, use multiSet() if you wish to set multiple items to different values.

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(…).multiSet( [ id ], val )

Get the current value(s) of a field.

Parameters:

Returns:

DataTable.Editor.Field:
The field instance for chaining.

Example

Increment a value for the rows being edited (number of tiems the row has been edited):

editor.edit(table.rows({ selected: true }).indexes());

// Get the ids of the rows being edited
var rows = editor.field('editCount').multiGet();

// Set each item value
$.each(rows, function (id, val) {
	editor.field('editCount').multiSet(id, val + 1);
});

Related

The following options are directly related and may also be useful in your application development.