Question on "Notice: Undefined index in ...\Editor\Field.php on line 578"

Question on "Notice: Undefined index in ...\Editor\Field.php on line 578"

pansengtatpansengtat Posts: 66Questions: 26Answers: 1

Hi,

I recently created a small web app that uses XAMPP (phpMyAdmin v4.1.12, PHP v5.5.11, Windows 8.1 x64), with two different tabs for two different DataTables tables.

The funny thing is that despite structuring my code for both tabs in both JS/PHP files in a similar fashion like what is shown here (http://editor.datatables.net/examples/simple/fieldTypes.html), the behaviorial outcomes are different. I don't know how to troubleshoot this issue, as I don't know if it is (a) a DataTables Editor bug, (b) faulty code in either PHP/JS, or (c) the way my SQL tables are joined.

Let me start with the code samples for the respective JS and PHP files:

JS File 1

var editor; // use a global for the submit and return data rendering in the examples

(function($){
    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor({
            ajax: "php/TRPlanningEditor.php",
            table: "#TRplanning",
            fields: [{
                    label: "Scheduled Start Date: ",
                    name: "TestRequestPlannedSchedule.ScheduledStartDate",
                    type: "date"
                },{
                    label: "Scheduled End Date: ",
                    name: "TestRequestPlannedSchedule.ScheduledEndDate",
                    type: "date"
                },{
                    label: "Scheduled Man Hours (Normal)",
                    name: "TestRequestPlannedSchedule.ScheduledManHrsNM"
                },{
                    label: "Scheduled Man Hours (OT - Wkday/Sat)",
                    name: "TestRequestPlannedSchedule.ScheduledManHrsOT"
                },{
                    label: "Scheduled Man Hours (OT - Sun/PH)",
                    name: "TestRequestPlannedSchedule.ScheduledManHrsOTSunPH"
                },{
                    label: "Remarks (Outsource): ",
                    name: "TestRequestAdv.RemarksOutsource"
                }
            ]
        } );
     
        $('#TRplanning').dataTable( {
            dom: "Tfrtip",
            ajax: "php/TRPlanningEditor.php",
            columns: [
                { data: "TestRequestPlannedSchedule.TestRequestNo" },
                { data: "TestRequestMain.ProjectID" },
                { data: "TestRequestMain.ProjectName" },
                { data: "TestRequestAdv.TestPlan" },
                { data: "TestEnvironment.Name" },
                { data: "TestRequestAdv.Release" },
                { data: "ConfirmationMirror.String" },
                { data: "TestRequestPlannedSchedule.ReqScheduleStartDate" },
                { data: "TestRequestPlannedSchedule.ReqScheduleEndDate" },
                { data: "TestRequestPlannedSchedule.ScheduledStartDate" },
                { data: "TestRequestPlannedSchedule.ScheduledEndDate" },
                { data: "TestRequestPlannedSchedule.ScheduledManHrsNM" },
                { data: "TestRequestPlannedSchedule.ScheduledManHrsOT" },
                { data: "TestRequestPlannedSchedule.ScheduledManHrsOTSunPH" },
                { data: "TestRequestAdv.RemarksOutsource" }
            ],
            tableTools: {
                sRowSelect: "os",
                aButtons: [
                    { sExtends: "editor_edit",   editor: editor}
                ]
            },
            initComplete: function(settings, json) {
            }
        } );
    } );
}(jQuery));

JS File 2

var editor; // use a global for the submit and return data rendering in the examples

(function($){
    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor({
            ajax: "php/TRRecordManHrsEditor.php",
            table: "#TRrecordmanhrs",
            fields: [{
                    label: "Actual Start Date: ",
                    name: "TestRequestActualSchedule.ActualStartDate",
                    type: "date"
                },{
                    label: "Actual End Date: ",
                    name: "TestRequestActualSchedule.ActualEndDate",
                    type: "date"
                },{
                    label: "Man Hours (Normal): ",
                    name: "TestRequestActualSchedule.ManHrsNM"
                },{
                    label: "Man Hours (OT - Wkday/Sat): ",
                    name: "TestRequestActualSchedule.ManHrsOT"
                },{
                    label: "Man Hours (OT - Sun/PH): ",
                    name: "TestRequestActualSchedule.ManHrsOTSunPH"
                },{
                    label: "Discrepancy Man Hours (Normal): ",
                    name: "TestRequestDiscrepancySchedule.DiffManHrsNM"
                },{
                    label: "Discrepancy Man Hours (OT - Wkday/Sat): ",
                    name: "TestRequestDiscrepancySchedule.DiffManHrsOT"
                },{
                    label: "Discrepancy Man Hours (OT - Sun/PH): ",
                    name: "TestRequestDiscrepancySchedule.DiffManHrsOTSunPH"
                },{
                    label: "Status: ",
                    name: "TestRequestMain.Status",
                    type: "select"
                },{
                    label: "Confirmation: ",
                    name: "TestRequestActualSchedule.Approval",
                    type: "select"
                },{
                    label: "Remarks (Admin):",
                    name: "TestRequestAdv.Remarks2"
                }
            ]
        } );
     
        $('#TRrecordmanhrs').dataTable( { // INCLUDE IDENTIFIER FOR THE FORM HERE.
            dom: "Tfrtip",
            ajax: "php/TRRecordManHrsEditor.php", // PHP CODE FOR THE EDITOR
            columns: [  //  COLUMN DATA TO BE DISPLAYED
                { data: "TestRequestActualSchedule.TestRequestNo" },
                { data: "TestRequestActualSchedule.TotalManHrs" },
                { data: "TestRequestActualSchedule.ActualStartDate" },
                { data: "TestRequestActualSchedule.ActualEndDate" },
                { data: "TestRequestActualSchedule.ManHrsNM" },
                { data: "TestRequestActualSchedule.ManHrsOT" },
                { data: "TestRequestActualSchedule.ManHrsOTSunPH" },
                { data: "TestRequestDiscrepancySchedule.DiffManHrsNM" },
                { data: "TestRequestDiscrepancySchedule.DiffManHrsOT" },
                { data: "TestRequestDiscrepancySchedule.DiffManHrsOTSunPH" },
                { data: "StatusMirror.String" },
                { data: "ConfirmationMirror.String" },
                { data: "TestRequestAdv.Remarks2" }
            ],
            tableTools: {
                sRowSelect: "os",
                aButtons: [
                    { sExtends: "editor_edit",   editor: editor}
                    // Give users an option to edit the information. Do note that functions such as adding new entries and deleting entries are available too. Check the examples in 
                    // localhost/taskscheduler/examples/
                ]
            },
            initComplete: function(settings, json) {    // This map to show dropdown options when using 'Edit' function
                editor.field('TestRequestActualSchedule.Approval').update(json.ConfirmationMirror);
                editor.field('TestRequestMain.Status').update(json.StatusMirror);
            }
        } );
    } );
}(jQuery));

For JS File 1, I have this error shown in the Ajax request by using the F12 Developer Tools in Chrome to debug:
Outcome for Tab 1

<b>Notice</b>:  Undefined index: SWQAEngineerID in <b>C:\xampp\htdocs\TaskScheduler1\php\lib\Editor\Field.php</b> on line <b>578</b><br />

{
"row":{
"DT_RowId":"row_4",
"TestRequestMain":{
"TestRequestNo":"4",
"ProjectID":"14_004",
"SWQAEngineerID":"1",
"AssignedGroupID":"5",
"Status":"1"}
,
"TestRequestAdv":{
"TestPlan":"Update update",
"TestEnvironmentID":"1",
"Release":"MP"}
,
"TestEnvironment":{
"Name":"PC"}
,
"Login":{
"Username":"Chris"}
,
"AssignedGroup":{
"Name":"Internal"}
,
"StatusMirror":{
"String":"Active"}
}
}

Whereas for JS File 2, I don't have the error, and both files returned a 200 OK status.
Outcome for Tab 2

{
"row":{
"DT_RowId":"row_4",
"TestRequestActualSchedule":{
"TestRequestNo":"4",
"TotalManHrs":"0.0",
"ActualStartDate":"2014-07-07",
"ActualEndDate":"2014-07-07",
"ManHrsNM":"3.0",
"ManHrsOT":"2.0",
"ManHrsOTSunPH":"0.0",
"Approval":"1"}
,
"TestRequestDiscrepancySchedule":{
"DiffManHrsNM":"0.0",
"DiffManHrsOT":"0.0",
"DiffManHrsOTSunPH":"0.0"}
,
"TestRequestMain":{
"Status":"1"}
,
"StatusMirror":{
"String":"Active"}
,
"ConfirmationMirror":{
"String":"Confirmed"}
,
"TestRequestAdv":{
"Remarks2":"Please proceed"}
}
}

So my question is that what 'undefined index' is DataTables Editor pointing to?
Is it that Editor is unable to find the key-value pair within DT_RowId array, that's why it is triggering an error for File 1 but not File 2?

Prior to asking this question, I have looked into (http://www.datatables.net/forums/discussion/20897/help-me-with-undefined-index-id) and (http://www.datatables.net/forums/discussion/14741/notice-undefined-index-secho) but after making modifications to the baseline code (Field.php) with the first link, there was no difference in outcome; the same error message can be found in Chrome > F12 Developer Tools > Network > Response.

What additional steps are available to debug this further and investigate?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin
    Answer ✓

    Hi,

    Are you able to link me to the page so I can take a look and debug it? I don't immediately see the issue from the above code. If you don't want to make the URL public, drop me an e-mail allan @ this domain.net.

    Allan

  • pansengtatpansengtat Posts: 66Questions: 26Answers: 1

    A workaround was discovered:

    For every respective Field::Inst('columnID_to_mirror'), Field::Inst('mirrorID') found inside 'fileEditor.php', add a hidden field in the 'fields' section in the 'fileEditor.js' file like this:

    $(document).ready(function() {
            editor = new $.fn.dataTable.Editor({
                ajax: "php/yourfileEditor.php",
                table: "#yourTableID",
                fields: [{
                        label: "Mirror Column String: ",
                        name: "maintable.columnID_to_mirror",
                        type: "hidden"
                    },{
                        // insert additional labels and table columns as desired
                    }
                ]
            } );
    
This discussion has been closed.