Editor: Issue with inline edit and create - records do not save

Editor: Issue with inline edit and create - records do not save

kmboninkmbonin Posts: 59Questions: 16Answers: 0

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

  • kmboninkmbonin Posts: 59Questions: 16Answers: 0

    controller:

    var response = new Editor(db, "logan_dvprTasks", "taskID")
                        .Debug(true)
                        .Model<DVPRTaskDataModel>()
                        .Field(new Field("logan_dvprTasks.taskID"))
                        .Field(new Field("logan_dvprTasks.dvprID"))
                        .Field(new Field("logan_dvprTasks.taskName"))
                        .Field(new Field("logan_dvprTasks.taskNumber")
                            .Options("logan_dvprTemplateTasks", "taskNumber", "taskName")
                            .Validator(Validation.DbValues()))
                        .Field(new Field("logan_dvprTasks.DisplayOrder"))
                        .Field(new Field("logan_dvprTasks.taskNotes"))
                        .Field(new Field("logan_dvprTasks.miscTaskName"))
                        .Field(new Field("logan_dvprTasks.taskCompleteYN"))
                        .Field(new Field("logan_dvprTasks.required"))
                        .Field(new Field("logan_dvprTasks.responsibleID")
                            .Options("logan_dept_dvpr", "deptID", "department")
                            .Validator(Validation.DbValues()))
                        .Field(new Field("logan_dvprTasks.resourceID")
                            .Options("logan_user_dvpr", "userID", "fullName")
                            .Validator(Validation.DbValues()))
                        .Field(new Field("logan_dvprTasks.estTime")
                            .Validator(Validation.Numeric()))
                        .Field(new Field("logan_dvprTasks.estStartDate")
                            .GetFormatter(Format.DateSqlToFormat("MM/d/yyyy"))
                            .SetFormatter(Format.DateFormatToSql("MM/d/yyyy")))
                        .Field(new Field("logan_dvprTasks.loggedIn"))
                        .Field(new Field("logan_dvprTasks.lastLoginDate")
                            .GetFormatter(Format.DateSqlToFormat("MM/d/yyyy"))
                            .SetFormatter(Format.DateFormatToSql("MM/d/yyyy")))
                        .Field(new Field("logan_dvprTasks.estCompDate")
                            .GetFormatter(Format.DateSqlToFormat("MM/d/yyyy"))
                            .SetFormatter(Format.DateFormatToSql("MM/d/yyyy")))
                        .Field(new Field("logan_dept_DVPR.department"))
                        .Field(new Field("logan_user_DVPR.fullName"))
                        .Field(new Field("logan_dvpr.dvprNumber"))
                        .Field(new Field("logan_dvpr.jobNumber"))
                        .Field(new Field("logan_dvpr.customerDesc"))
                        .LeftJoin("logan_dept_DVPR", "logan_dept_DVPR.deptID", "=", "logan_dvprTasks.responsibleID")
                        .LeftJoin("logan_user_DVPR", "logan_user_DVPR.userID", "=", "logan_dvprTasks.resourceID")
                        .LeftJoin("logan_dvpr", "logan_dvpr.dvprID", "=", "logan_dvprTasks.dvprID")
                        .MJoin(
                            new MJoin("logan_dvpr_timeLog")
                            .Link("logan_dvprTasks.taskID", "logan_dvpr_timeLog.taskID")
                            .Where("logan_dvpr_timeLog.userID", userID, "=")
                            .Field(new Field("logan_dvpr_timeLog.taskID"))
                            .Field(new Field("logan_dvpr_timeLog.userID"))
                            .Field(new Field("logan_dvpr_timeLog.loggedINYN"))
                            .Field(new Field("logan_dvpr_timeLog.timeOUT")
                                .GetFormatter(Format.DateSqlToFormat("MM/d/yyyy"))
                                .SetFormatter(Format.DateFormatToSql("MM/d/yyyy")))
                            .Field(new Field("logan_dvpr_timeLog.timeIN")
                                .GetFormatter(Format.DateSqlToFormat("MM/d/yyyy"))
                                .SetFormatter(Format.DateFormatToSql("MM/d/yyyy")))
                            
                        )
                        .Where("logan_dvprTasks.dvprID", dvprID, "=");
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    What does the server return when you edit a row? Your browser's developer tools will let you see the Ajax response.

    Allan

  • kmboninkmbonin Posts: 59Questions: 16Answers: 0

    Here's the error in the JSON response:

    {"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Length cannot be less than
     zero.\r\nParameter name: length","fieldErrors":[],"id":null,"meta":{},"options":{},"files":{},"upload"
    :{"id":null},"debugSql":[{"Query":"SELECT  * FROM  logan_dvprTasks WHERE [logan_dvprTasks].[taskID] 
    = @where_0 ","Bindings":[{"Name":"@where_0","Value":"1383","Type":null}]},{"Query":"UPDATE  logan_dvprTasks
     SET  [taskNotes] = @taskNotes WHERE [logan_dvprTasks].[taskID] = @where_0 ","Bindings":[{"Name":"@taskNotes"
    ,"Value":"R&amp;D No PO Required&#10;Testing","Type":null},{"Name":"@where_0","Value":"1383","Type":null
    }]}
    

    Not sure what "Length cannot be less than zero..parameter name length is??

  • kmboninkmbonin Posts: 59Questions: 16Answers: 0

    Also, this is the same error that is thrown on each field...

  • kmboninkmbonin Posts: 59Questions: 16Answers: 0

    Figured it out. Issue was with a postEdit logging I was doing.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Thanks for posting back - good to hear you've got it sorted out.

    Allan

This discussion has been closed.