The columns.editField option is compared to fields.data instead of fields.name
The columns.editField option is compared to fields.data instead of fields.name
tldr see first comment
The columns.editField
does not behave correctly. Its value should be compared to the names of the fields, like it says in the documentation.
The values this option can take are defined by the field names that are used for the Editor form (
fields.name
). Any field name defined in the Editor instance can be used as a value here.
This is not how it is implemented! Instead of the field names, the value is compared to the value of fields.data
.
The reason why it still works 9 out of 10 times is because fields.data
is set to fields.name
if not specified.
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.
The case when it breaks is when you set fields.data
to something special, like a function.
// in DataTable options
columns: [
{
name: "first_name",
data: function ( data, type, set ) {
if ( type === 'set' ) {
data.name = set;
}
return data.name.split(' ')[0];
}
editField: "first_name"
}
]
// In Editor options
fields: [
{
name: "first_name",
data: function ( data, type, set ) {
if ( type === 'set' ) {
data.name = set;
}
return data.name.split(' ')[0];
},
label: "First name:"
}
]
Here, the first_name
is a computed field/column. I expect this to work because the column has an editField
that references an existing field name. However, this code throws an exception somewhere inside the __dtFieldsFromId
function.
Uncaught Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11
Replies
tldr: in
__dtFieldsFromIdx
replace this:Replace with:
Completely agree thank you! Will be fixed in the next release.
Allan
Just to confirm, this change will be in v1.6.2 when it is released (in the next week or so).
Regards,
Allan