Editor: Create row onClick
Editor: Create row onClick
kmbonin
Posts: 59Questions: 16Answers: 0
Trying to create a new row with the only two required fields my logan_prodData table needs: dateAdded and JobID (FK to logan_jobs). I'm getting the error: table id=ProductionData - Column 'jobID' in field list is ambiguous
What am I doing wrong?
Controller:
using (var db = new Database(settings.DbType, settings.DbConnection))
{
var response = new Editor(db, "logan_prodData", "recordID")
.Model<ProductionJobsDataModel>()
.Field(new Field("logan_prodData.PComp")
.Validator(Validation.Numeric()))
.Field(new Field("logan_prodData.CurEstEndDate")
.GetFormatter(Format.DateSqlToFormat("MM/d/yyyy"))
.SetFormatter(Format.DateFormatToSql("MM/d/yyyy")))
.Field(new Field("logan_prodData.PMEnd")
.GetFormatter(Format.DateSqlToFormat("MM/d/yyyy"))
.SetFormatter(Format.DateFormatToSql("MM/d/yyyy")))
.Field(new Field("logan_prodData.recordID"))
.Field(new Field("logan_prodData.jobID"))
.Field(new Field("logan_prodData.deptID")
.Options("logan_dept", "deptID", "department")
.Validator(Validation.DbValues()))
.Field(new Field("logan_jobs.jobNumber"))
.Field(new Field("logan_jobs.customer"))
.Field(new Field("logan_jobs.plannerID")
.Options("logan_user", "userID", "fullName", q => q.Where("deptID", "1", "="))
.Validator(Validation.DbValues()))
.Field(new Field("logan_jobs.description"))
.Field(new Field("logan_jobs.partNumber"))
.Field(new Field("logan_user.fullName"))
.Field(new Field("logan_status.status"))
.Field(new Field("logan_status.displayColor"))
.Field(new Field("logan_dept.department"))
.LeftJoin("logan_jobs", "logan_jobs.jobId", "=", "logan_prodData.jobId")
.LeftJoin("logan_dept", "logan_dept.deptID", "=", "logan_prodData.deptID")
.LeftJoin("logan_status", "logan_status.statusID", "=", "logan_prodData.statusID")
.LeftJoin("logan_user", "logan_user.userID", "=", "logan_jobs.plannerID")
.Process(request)
.Data();
JS to create row onClick:
$('#ProductionData tbody').on('click', 'a.editor_create', function (e) {
e.preventDefault();
var cellContents = table.cell( ($(this).closest('tr').next('tr')),1).data()
editor
.create(false)
.val('logan_prodData.jobID', cellContents)
.val('logan_prodData.dateAdded', Date.now())
.submit();
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Just modified my model and the error cleared. When I perform the onClick action, though, I get the error:
TypeError: fields[n] is undefined
fields[ n ].set( v );
in file dataTables.editor.js.
Any idea what this error is?
Are you able to give me a link to the page so I can try to debug it please? My guess is that there isn't a field with the name
logan_prodData.jobID
, but I'm not sure as the Javascript initialisation isn't included above.Regards,
Allan
Can't give you a link to the page as it's an internal company page that I am developing on their server. Here's my debug support request code if that helps:
DataTables debug bookmarklet
Upload complete - debug code: amelox
And here is the initialization code:
Thanks for the code. It does indeed appear that there is no Editor field by the name of
logan_prodData.jobID
.If you want to be able to set that field using the code
.val('logan_prodData.jobID', cellContents)
you'd need to have a field with that name.Allan
Okay, I got it working, but then my group sorting was conflicting with the results, so I modified the group to display in two cells instead of one, then changed the classes appropriately. The sort works fine, but my row creation no longer works, and I get this error when I try to invoke it:
TypeError: editor.create(...).val(...).submit is not a function
editor
I have verified that the add row code is being called and has the correct JobID to be inserted. It just doesn't seem to know what "editor" is anymore.
Full JS: (includes a row-details controller with info which is the first function).
It is a global
editor
variable that you are using. It would probably be best to usevar editor = new $.fn.dataTable.Editor( {...
.Also, could
cellContent
be undefined? If so,val()
will return a value, not an Editor instance.Allan
Okay, so I added the var declaration to line 25 (see above code post) so that it now reads var editor...
But no luck. Still says the TypeError: editor.create(...).val(...).submit is not a function.
Any other ideas?
Could
cellContent
be undefined?What happens if you break the chain up? e.g.:
Allan
So I broke up the chain, and that worked, but cellContent is, in fact, undefined. But I'm not sure why?? Column index 1 is the jobID, and that is never null. I'm getting the closest <tr> to the image which is in a group (see attachment, green icon on the gray rows).
Good - that explains why the chaining didn't work then.
val
is returning the values rather than an Editor instance.I'd need a link to the page to be able to debug it fully, but perhaps try:
Allan
Figured it out (finally). When using the group functionality, which creates a row above the target group of rows, the ID is actually in the next <tr>, not the group <tr>. So this worked, for anyone who is following this thread:
var cellContents = table.cell($(this).closest('tr').next('tr'), 1).data();
Good to hear you've got it working now! Thanks for posting back.
Allan