fields.data

Since: Editor 1.3

Data property from the data source object to use as the data for this field.
Please note - this property requires the Editor extension for DataTables.

Description

This option provides the field with the information that it needs in order to know which data property from the source object should be used as the value of this field. For example, consider the data structure:

{
    "name": "Tiger Nixon",
    "position": "System Architect",
    "salary": "$320,800",
    "start_date": "2011/04/25",
    "office": "Edinburgh",
    "extn": "5421"
}

To configure a field to use the salary field you would set this option to salary. Likewise, to use the office use office.

By default, if not given in the initialisation of the field, it is automatically set to match the value of the fields.name property. This is by far the most common use case - as it helps keep things simple, but it is possible with this option to perform complex data transformations if needed.

fields.data as the same abilities as the DataTables columns.data property, in that it can read deeply nested data using dotted Javascript object notation and can even be given as a function. Please refer to the columns.data documentation for the full range of options available.

Backwards compatibility note

In previous versions of Editor (1.2-) this was called dataProp. It has been renamed for simplification and harmonisation with DataTables (columns.data). The old name can still be used for backwards compatibility, but the new form is preferred.

Type

This option can be given in the following type(s):

Examples

Explicitly setting the data property. Note that this is actually redundant since data is automatically set to name if data is not given.:

var editor = new DataTable.Editor({
	ajax: 'php/staff.php',
	table: '#myTable',
	fields: [
		{
			label: 'First name:',
			name: 'first_name',
			data: 'first_name'
		}
	]
});

Read data from a nested object:

var editor = new DataTable.Editor({
	ajax: 'php/staff.php',
	table: '#myTable',
	fields: [
		{
			label: 'First name:',
			name: 'first_name',
			data: 'name.first'
		}
	]
});

Use a function to get the data:

var editor = new DataTable.Editor({
	ajax: 'php/staff.php',
	table: '#myTable',
	fields: [
		{
			label: 'First name:',
			name: 'first_name',
			data: function (data, type, set) {
				if (type === 'set') {
					data.name = set;
				}
				return data.name.split(' ')[0];
			}
		}
	]
});