Editor: Issue with inline edit and create - records do not save
Editor: Issue with inline edit and create - records do not save
Having an issue with inline editing and record creation. On inline edit, I click a field, the textbox appears and I can change the data. However, when I press enter or click another field (onblur action) it does not save, even though I have told it to save onblur. Similar thing with the create...I can add the record, it appears to save, but does not save to the database nor appears in the table. No errors are showing up, just the lock on the field for inline editing.
The only thing I am doing differently here is an mjoin...could that be causing the issue? I can edit using the dialog just fine...
js
var dvprID = getParameterByName('dvprID');
var editor;
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
ajax: './api/DVPRTaskData/DVPRTaskData/' + dvprID,
table: "#ProductionData",
fixedHeader: true,
fields: [
{
"label": "Display Order:",
"name": "logan_dvprTasks.DisplayOrder",
"def": 1
},
{
"label": "Task Complete:",
"name": "logan_dvprTasks.taskCompleteYN",
"type": "radio",
"def": "0",
"options": [
{ label: "Yes", value: "1" },
{ label: "No", value: "0" }
]
},
{
"label": "Responsible:",
"name": "logan_dvprTasks.responsibleID",
"type": "select",
"placeholder": "Select"
},
{
"label": "Task Name:",
"name": "logan_dvprTasks.taskNumber",
"type": "select"
},
{
"label": "Responsible Resource:",
"name": "logan_dvprTasks.resourceID",
"type": "select",
"placeholder": "Select"
},
{
"label": "Misc. Task Name/Desc:",
"name": "logan_dvprTasks.miscTaskName"
},
{
"label": "Est. Start Date:",
"name": "logan_dvprTasks.estStartDate",
"type": "date",
"def": function () { return new Date(); },
"dateFormat": "mm/dd/yy"
},
{
"label": "Est Complete Date:",
"name": "logan_dvprTasks.estCompDate",
"type": "date",
"def": function () { return new Date(); },
"dateFormat": "mm/dd/yy"
},
{
"label": "Est time:",
"name": "logan_dvprTasks.estTime"
},
{
"label": "Required?:",
"name": "logan_dvprTasks.required",
"type": "radio",
"def": "1",
"options": [
{ label: "Yes", value: "1" },
{ label: "No", value: "0" }
],
},
{
"label": "Task Notes:",
"name": "logan_dvprTasks.taskNotes",
"type": "textarea"
},
{
"label": "Log In?:",
"name": "logan_dvprTasks.loggedIn",
"className": "readonly"
},
{
"label": "Last Login Date:",
"name": "logan_dvprTasks.lastLoginDate",
"type": "date",
"def": function () { return new Date(); },
"dateFormat": "mm/dd/yy",
"className": "readonly"
}
],
formOptions: {
inline: {
onBlur: 'submit'
}
}
});
$('#ProductionData').on('click', 'tbody td:not(:first-child,:nth-child(1),:nth-child(2),:nth-child(3),:nth-child(9),:last-child)', function (e) {
editor.inline(this, {
onBlur: 'submit'
});
});
var table = $('#ProductionData').DataTable( {
ajax: './api/DVPRTaskData/DVPRTaskData/' + dvprID,
order: [0, 'asc'],
fixedHeader: true,
columns: [
{
"data": "logan_dvprTasks.DisplayOrder", "className": "reorder"
},
{
"data": function (data, type, row) {
return data.logan_dvpr.dvprNumber + ' - ' + data.logan_dvpr.customerDesc;
},
"visible": false, "targets": 2
},
{
"data": "logan_dvprTasks.taskNumber"
},
{
"data": null,
"render": function ( data, type, row ) {
var misc = "";
if (data.logan_dvprTasks.miscTaskName != null) misc = data.logan_dvprTasks.miscTaskName;
return data.logan_dvprTasks.taskName + ' ' + misc;
}
},
{
"data": "logan_dept_DVPR.department", "className": "editable", "editField": "logan_dvprTasks.responsibleID"
},
{
"data": "logan_user_DVPR.fullName", "className": "editable", "editField": "logan_dvprTasks.resourceID"
},
{
"data": "logan_dvprTasks.estStartDate", "className": "editable", "editField": "logan_dvprTasks.estStartDate"
},
{
"data": "logan_dvprTasks.estCompDate", "className": "editable", "editField": "logan_dvprTasks.estCompDate"
},
{
"data": "logan_dvprTasks.estTime", "className": "editable", "editField": "logan_dvprTasks.estTime"
},
{
"data": "logan_dvprTasks.taskNotes", "className": "editable", "editField": "logan_dvprTasks.taskNotes"
},
{
"className": "details-control loggedOut",
"orderable": false,
"data": "logan_dvpr_timeLog[, ].logan_dvpr_timeLog.loggedINYN",
"defaultContent": "",
"createdCell": function (td, cellData, rowData, row, co) {
var color = 'rgba(255, 255, 255, 0.1)';
$(td).css('color', color);
if (cellData == "Y") {
$(td).removeClass("loggedOut");
$(td).addClass("loggedIn");
}
},
},
{
"data": null,
"defaultContent": "",
"orderable": false,
"className": "select-checkbox"
},
],
columnDefs: [
{ orderable: false, targets: [ 0,1,2,3,4,5,6,7,8,9 ] }
],
rowReorder: {
dataSrc: "logan_dvprTasks.DisplayOrder",
editor: editor
},
select: {
style: 'os',
selector: 'td:last-child'
},
lengthChange: true,
lengthMenu: [[10, 25, 50, 75, -1], [10, 25, 50, 75, "All"]],
pageLength: 50,
drawCallback: function (settings) {
var api = this.api();
var rows = api.rows({ page: 'current' }).nodes();
var last = null;
api.column(1, { page: 'current' }).data().each(function (group, i) {
if (last !== group) {
$(rows).eq(i).before(
'<tr><td colspan="5" class="group"> ' + group + '</td></tr>'
);
last = group;
}
});
}
});
new $.fn.dataTable.Buttons(table, [
{
extend: "create",
editor: editor,
formButtons: [
'Save',
{ label: 'Cancel', fn: function () { this.close(); } }
]
},
{
extend: "edit",
editor: editor,
formButtons: [
'Save',
{ label: 'Cancel', fn: function () { this.close(); } }
]
},
{
extend: "remove",
editor: editor,
formMessage: function (e, dt) {
return 'Are you sure you want to delete this record?';
},
formButtons: [
'Delete',
{ label: 'Cancel', fn: function () { this.close(); } }
]
},
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
]);
table.buttons().container()
.prependTo($('div.fg-toolbar:eq(0)', table.table().container()));
What am I doing wrong?
Answers
controller:
What does the server return when you edit a row? Your browser's developer tools will let you see the Ajax response.
Allan
Here's the error in the JSON response:
Not sure what "Length cannot be less than zero..parameter name length is??
Also, this is the same error that is thrown on each field...
Figured it out. Issue was with a postEdit logging I was doing.
Thanks for posting back - good to hear you've got it sorted out.
Allan