Key entered - get "Unable to automatically determine field from source"
Key entered - get "Unable to automatically determine field from source"
I'm using the Editor with my datatable to handle inline edits of various cells in my table. The table column change based on values selected by the user in a drop down. I basically have to then get the data from the database, figure out some things with columns, then refresh the table (along with creating an editor instance). The user can change a cell - that's were I'm having problems.
I’ve added these two statements to my code:
$('#example').on('click', 'tbody td:not(:first-child)', function (e) {
// debugger;
crntCell = table.cell(this);
crntColumnHandle = crntCell[0];
crntColumnNbr = crntColumnHandle[0].column;
crntRowNbr = crntColumnHandle[0].row;
editor.inline(this, crntColumnNbr.toString());
});
// Inline editing on tab focus
table.on('key-focus', function (e, datatable, cell) {
// debugger;
var myCell = cell.index();
crntColumnNbr = myCell.column;
crntRowNbr = myCell.row;
editor.inline(cell.index(), crntColumnNbr.toString());
});
The above code solved the “Unable to automatically determine field from source” error I was getting initially. This is using approach 2 described for the inline api, specify the field name.
Note, I’m using an array, hence the column number is my field name (correct me if I’m wrong). I've like to avoid having to assign an editor to each column since at run-time I'd have to figure out how to do this.
When I press a key to change the cell, I get “Unable to automatically determine field from source”
What basic step have I missed? Or what else do I need to add?
This question has an accepted answers - jump to answer
Answers
Hi,
Thanks for your question. With the above you should be able to simply use:
The
key-focus
event will trigger when you click on a focusable cell.I've also dropped the second argument to
inline()
as that shouldn't be needed if thecolumns.editField
property is used. That property is also what would need to be used to resolve the "Unable to automatically..." issue.Basically what is happening is that the
columns.data
property for a field is not exactly matching up with a field in the Editor (fields.name
) - therefore Editor doesn't know which field it should be editing.You can see that effect in the final column in this example where
sites.name
is the data shown in the column butusers.site
is the field to be edited.Regards,
Allan
I don’t think it will be easy to add a column.editField option property.
A subset of the columns for the table on my web page change dynamically, based on a value they select in a drop down that pulls data for the table.
Also, the columns they can edit is controlled by a setup page. And on top of everything, they control the column name.
We also have authorization to, some end user can edit; others can not. At run time I determine the edit state of the web page. If can’t edit, I don’t need the editor. If can edit, we enable an edit button – when selected, I need to enable columns according to what they defined as “edit”. When they are done with the edit, i'll need to update calculated columns and persist the changes to the database.
On initial display of the table I need to sum columns (which also are user controlled to specify). Once I have the edit capability working, the algorithm will need to execute again.
The code is working for the initial displaying of data. I’m adding the edit capability now. Right or wrong, I get the data and work with the column heading then the actual data contained in an array; check some things, then create the Editor instance and table instance.
Conclusion, I don't see an easy way to add and editor property to the columns. I will attempt to post another comment with code snippets of interest.
Perfect - thank you for the code.
Change:
to be:
I believe that should resolve the issue. You are using column indexes for the data indexes to store the data, so
fields.data
will also use the index.Its the
.toString()
that is causing the issue - it means that a strict type check (which Editor uses) will fail for column indexes - i.e.1 === '1'
isfalse
.Editor has the ability to use a different name from its data point, which is why the above should work.
Having said that, I think you could also just use:
I haven't tested it, but I can't think off the top of my head why it wouldn't work...
Regards,
Allan
That did the trick, thanks.