field().val()

Since: Editor 1.3

Get / set the value of a field.
Please note - this property requires the Editor extension for DataTables.

Description

It is often useful to be able to get and set the value of a field, for example in client-side validation, or data manipulation. This method provides that ability.

When used while multi-row editing, this method has the following behaviour:

  • As a getter:
    • If all items being edited have the same value for this field, that value is returned
    • If the items being edited have different values for this field, undefined is returned. field().multiGet() should be used to access individual values if this is the case.
  • As a setter:
    • The field value is set to the same value for all items being edited. Use field().multiSet() to set individual values if required.

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.

Types

field(…).val()

Get the field's value

Returns:

Any: The field's value or undefined if multi-row editing and the items being edited have different values for this field.

field(…).val( value )

Set the field's value

Parameters:

Returns:

DataTable.Editor.Field: Field instance

Example

Edit a row, using val() to set values and then submit() to immediately submit the form without user interaction:

editor.edit(row, false);
editor.field('name').val('Updated name');
editor.field('access').val('Read only');
editor.submit();

Related

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