Why this message is throws when I select a row from the table: "Uncaught Unable to automatically determine field from source. Please specify the field name"?
I don't have a record of a license for your Editor install. Could you confirm which user name account you purchased Editor under, or are using the trial from?
I presume you are using the inline() or bubble() methods here? The issue is that Editor can't determine the name based on the cell that activated the action. There are a number of reasons this can occur. Can you post your initialisation code so I can take a look?
i have same issue.also i use MVC.Jquery.Datatables.net in MVC .net.
my editor config is :
var editor = new $.fn.dataTable.Editor({
ajax: "../php/staff.php",
table: '#ActivityItem',
fields: [
{ label: 'First name', name: 'FromTime' }
// etc
],
});
and i use
$('#ActivityItem').on('click', 'tbody td:not(:first-child)', function () {
editor.inline(this);
});
so with this code my datatable generated as well.
and finially js scripts:
"~/Scripts/jquery-2.1.1.js",
"~/Scripts/Datatables/jquery.dataTables.js",
"~/Scripts/Datatables/dataTables.tableTools.js",
"~/Scripts/Datatables/dataTables.bootstrap.js"
<script src="~/Scripts/Datatables/dataTables.editor.js"></script>
<script>
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function () {
var editor = new $.fn.dataTable.Editor({
ajax: "/Activity/editorPage",
table: '#ActivityItem',
fields: [
{ label: 'First name', name: 'FromTime' }
// etc
],
});
$('#ActivityItem').on('click', 'tbody td:not(:first-child)', function () {
editor.inline(this);
});
});
</script>
Thanks very much for the information. So based on your code above, the Ajax source is presenting the data for the DataTable as arrays - is that correct? However, Editor has been configures to use object (i.e. name: 'FromTime'). So the error you are getting is because Editor can't find a field that is to be edited from the data int he table (i.e. the array index integer).
The "fix" is to be consistent - either use objects everywhere, or configure Editor to use arrays. Technically you can use fields.data and fields.name to mix the two, but I would suggest that you will find it much easier if you use the same data type for both!
My own suggestion would be to use objects for everything - that will involve a change to your Ajax data source to return objects, rather than arrays for each row of data.
Interesting - that looks like it should work okay to me. Sorry for not being able to answer it straight out. Could you run the table through the debugger and let me know what the debug code is?
Click any of the content under the "Created" field, and it'll trigger this: "Uncaught Unable to automatically determine field from source. Please specify the field name"
If I make a created field in the Editor config, how can I prevent it from being editable? It's a non-editable column that's made when an item is created.
Is this still about the created column throwing 'Unable to automatically determine field from source'? I hadn't realised that was still an issue with your previous question (i.e. I didn't realise it was linked to the one before). As such my solution wasn't really valid since it doesn't resolve that issue.
You need to add a class to the editable columns (at least this is the way I would recommend doing it) using columns.className - add editable and then in your Javascript that calls inline() modify it to select only cells which have that class.
Answers
Hi,
I don't have a record of a license for your Editor install. Could you confirm which user name account you purchased Editor under, or are using the trial from?
I presume you are using the
inline()
orbubble()
methods here? The issue is that Editor can't determine the name based on the cell that activated the action. There are a number of reasons this can occur. Can you post your initialisation code so I can take a look?Thanks,
Allan
i have same issue.also i use MVC.Jquery.Datatables.net in MVC .net.
my editor config is :
var editor = new $.fn.dataTable.Editor({
ajax: "../php/staff.php",
table: '#ActivityItem',
fields: [
{ label: 'First name', name: 'FromTime' }
// etc
],
and i use
$('#ActivityItem').on('click', 'tbody td:not(:first-child)', function () {
editor.inline(this);
});
@Mahdi_Farhani - Are you able to link me to the page, or post your full Javascritp code so I can take a look?
Thanks,
Allan
Thank's for your attention. unfortunately it's not online page but this is all scripts i used.
at first the css :
(i add this stylesheet by bundling)
after that i tyr to add datatable into my page :
so with this code my datatable generated as well.
and finially js scripts:
Can you show me how you initialise your DataTable as well please?
Allan
Hi,
Thanks very much for the information. So based on your code above, the Ajax source is presenting the data for the DataTable as arrays - is that correct? However, Editor has been configures to use object (i.e.
name: 'FromTime'
). So the error you are getting is because Editor can't find a field that is to be edited from the data int he table (i.e. the array index integer).The "fix" is to be consistent - either use objects everywhere, or configure Editor to use arrays. Technically you can use
fields.data
andfields.name
to mix the two, but I would suggest that you will find it much easier if you use the same data type for both!My own suggestion would be to use objects for everything - that will involve a change to your Ajax data source to return objects, rather than arrays for each row of data.
Regards,
Allan
Hi,
this is my Json structure i've returned data from ajax source
Thanks for the information. As I suggested, I would recommend using objects, rather than arrays. See: http://datatables.net/manual/data#Objects .
Allan
Allan, can you explain how to use objects rather than arrays? I get the same "Uncaught" message as the OP with this configuration:
What is your file "../stack/plugins/datatables/php/table.qpidvulh_to-do_list.php" returning?
From your configuration it should be:
Allan
This is everything that's in the "../stack/plugins/datatables/php/table.qpidvulh_to-do_list.php" file:
Interesting - that looks like it should work okay to me. Sorry for not being able to answer it straight out. Could you run the table through the debugger and let me know what the debug code is?
Allan
As a follow-up, I can't run my page through the debugger because it only runs over https.
Apologies - I've just altered the bookmarklet to work on https as well. You'll need to delete the existing bookmarklet in your browser.
Allan
Forgot I still have this issue, and got the debugger to work: https://debug.datatables.net/oluwif
The issue can be seen on this page: https://www.dcturano.com/to-do_list/
Click any of the content under the "Created" field, and it'll trigger this: "Uncaught Unable to automatically determine field from source. Please specify the field name"
I don't see a
created
field in the Editor configuration, which is why the error is occurring.Allan
If I make a created field in the Editor config, how can I prevent it from being editable? It's a non-editable column that's made when an item is created.
You could use the
hidden
field type.Or in the PHP add
->set( false )
to the Field instance for that field to stop the libraries trying to set a value for it.Allan
This is currently the PHP for the created field:
I tried changing set to false and it's still throwing the error.
Is this still about the
created
column throwing 'Unable to automatically determine field from source'? I hadn't realised that was still an issue with your previous question (i.e. I didn't realise it was linked to the one before). As such my solution wasn't really valid since it doesn't resolve that issue.You need to add a class to the editable columns (at least this is the way I would recommend doing it) using
columns.className
- addeditable
and then in your Javascript that callsinline()
modify it to select only cells which have that class.Allan
Forgot to say that your last comment fixed the issue, thanks Allan.