Is there a way to use more than one nested type: "datatable" field in editor?

Is there a way to use more than one nested type: "datatable" field in editor?

Stacey1134Stacey1134 Posts: 112Questions: 20Answers: 0
edited January 10 in Free community support

I can successfully use one nested datatables field in editor. However, when I try to use 3, the data from the datatables fields are not passed to their respective editors. It's not an options pair issue because I can create a new record and use the nested datatables (all three of them) and select the values/items I want. But when I try to use the nested editor attached no data is passed.

I have a test case at but it is on a locked site, Allan, you have access to it already. rts.php where it's working with the 2nd and 3rd datatable instances remarked out. rts2.php , is what I want, but it will not return any data to the nested editors.

rts2.php "relevant part"

   <script>
        $(document).ready(function() {

            var comradeEditor = new $.fn.dataTable.Editor( {
                ajax: 'comradeNested.php',
                fields: [ {
                            label: 'Contact ID:',
                            name: 'form.CR_ID',
                            type: 'hidden'
                        }, {
                            label: 'Prison ID:',
                            name: 'form.PrisonerID'
                        }, {
                            label: 'First Name:',
                            name: 'form.FirstName'
                        }, {
                            label: 'Last Name:',
                            name: 'form.LastName'
                        }, {
                            label: 'Preferred Name:',
                            name: 'form.PrefName'
                        }, {
                            label: 'Subscribed to the Abby:',                    
                            name:  "form.IsAbby",
                            className: 'full block' ,
                            type:  "radio",
                            options: [
                                { label: "No", value: 0},
                                { label: "Yes", value: 1}
                            ],
                            def: 0
                        }, {
                            label: 'Prison Name:',
                            name: 'form.FAC_ID',
                            type: 'datatable'

                        }
                    ],
                bootstrap: {
                    floatingLabels: true
                }            
            } );

            var letterEditor = new $.fn.dataTable.Editor( {
                ajax: 'letterNested.php',
                fields: [ {
                            label: 'Letter ID:',
                            name: 'scanned_mail.id'
                        }, {
                            label: 'Orig Postmark:',
                            name: 'scanned_mail.postmark_date'
                        }, {
                            label: 'Scanned By:',
                            name: 'scanned_mail.scanner'
                        }, {
                            label: 'Answered By:',
                            name: 'scanned_mail.answered_by'
                        }, {
                            label: 'Printed By:',
                            name: 'scanned_mail.printed_by'
                        }, {
                            label: 'Date Printed:',
                            name: 'scanned_mail.date_printed'
                        }, {
                            label: 'Response Sent',
                            name: 'scanned_mail.response'
                        }, {
                            label: 'Resources Sent:',
                            name: 'scanned_mail.resources'                           
                        }
                    ],
                bootstrap: {
                    floatingLabels: true
                }            
            } );

            var facilityEditor = new $.fn.dataTable.Editor( {
                ajax: 'facilityNested.php',
                fields: [ {
                            label: 'Facility ID:',
                            name: 'PrisonFacilityListing.Facility_ID',
                            type: 'hidden'
                        }, {
                            label: 'Facility Type:',
                            name: 'PrisonFacilityListing.Facility_Type'
                        }, {
                            label: 'City:',
                            name: 'PrisonFacilityListing.City'
                        }, {
                            label: 'State:',
                            name: 'PrisonFacilityListing.State'
                        }, {
                            label: 'Phone:',
                            name: 'PrisonFacilityListing.Phone_Number'
                        }, {
                            label: 'Is mailing address Scanning Center?',                    
                            name:  "PrisonFacilityListing.scanning_center",
                            className: 'full block' ,
                            type:  "radio",
                            options: [
                                { label: "No", value: 0},
                                { label: "Yes", value: 1}
                            ],
                            def: 0
                        }, {
                            label: 'Prison Name:',
                            name: 'PrisonFacilityListing.Prison_Name'
                        }, {
                            label: 'Mailing Addr 1:',
                            name: 'PrisonFacilityListing.Mail_Addr_1'
                        }, {
                            label: 'Mailing Addr 2:',
                            name: 'PrisonFacilityListing.Mail_Addr_2'
                        }, {
                            label: 'Mailing Addr 3:',
                            name: 'PrisonFacilityListing.Mail_Addr_3'
                        }, {
                            label: 'Mailing City:',
                            name: 'PrisonFacilityListing.Mail_City'
                        }, {
                            label: 'Mailing State:',
                            name: 'PrisonFacilityListing.Mail_State'
                        }, {
                            label: 'Mailing Zipcode:',
                            name: 'PrisonFacilityListing.Mail_Zip'

                        }
                    ],
                bootstrap: {
                    floatingLabels: true
                }            
            } );

This question has an accepted answers - jump to answer

Answers

  • Stacey1134Stacey1134 Posts: 112Questions: 20Answers: 0
    edited January 10
               var editor = new DataTable.Editor({
                    ajax: "ajaxRts.php",
                    table: "#rts",
                    display: "bootstrap",
                    fields: [
                        {
                            label: 'RTS ID:',
                            name: 'returntosender.id',
                            type: 'hidden'
                        }, {
                            // label: 'Contact ID:',
                            // name: 'returntosender.cr_id',
                            // type: 'select'
                            label: 'Comrade Lookup:',
                            name: 'returntosender.cr_id',
                            type: 'datatable',
                            editor: comradeEditor,
                            optionsPair: {
                                value: 'form.CR_ID',
                            },
                            config: {
                                ajax: 'comradeNested.php',
                                buttons: [
    
                                    { extend: "create", className: 'btn btn-success',
                                        text: '<i class="fa-solid fa-user-plus"></i> New Comrade', 
                                        titleAttr: 'Add New Comrade', editor: comradeEditor, formTitle: 'Add New Comrade' 
                                    },
                                    { extend: "edit", className: 'btn btn-warning', 
                                        text: '<i class="fa-solid fa-user-pen"></i> Edit Comrade', 
                                        titleAttr: 'Edit Comrade', editor: comradeEditor, formTitle: 'Edit Comrade',  
                                        formButtons: [
                                        {
                                            text: 'Cancel',
                                            action: function () { this.close(); },
                                            className: 'btn btn-secondary'
                                        }, {
                                            text: 'Update',
                                            action: function () { this.submit(); },
                                            className: 'btn btn-primary'
                                        }
                                    ] 
    
                                    }
    
                                ],
                                columns: [{
                                        title: 'Contact ID',
                                        data: 'form.CR_ID'
                                    },{
                                        title: 'Preferred Name',
                                        data: 'form.PrefName'
                                    },{
                                        title: 'First Name',
                                        data: 'form.FirstName'
                                    },{
                                        title: 'Last Name',
                                        data: 'form.LastName'
                                    },{
                                        title: 'Prisoner ID',
                                        data: 'form.PrisonerID'
                                    },{
                                        title: 'Abby Subscriber',
                                        data: "form.IsAbby", 
                                        render: function (val, type, row) {
                                            return val == 0 ? "No" : "Yes";
                                        }  
                                    }                                
                                ],
                                lengthMenu: [[5,10,20,-1],[5,10,20,"All"]],
                                pageLength: 5,
                                autoWidth: true,
                                select: true
                            }                        
    
  • Stacey1134Stacey1134 Posts: 112Questions: 20Answers: 0
    edited January 10
                        }, {
                            // label: 'Orig. Letter ID:',
                            // name: 'returntosender.let_id',
                            // type: 'select'
                            label: 'Letter Lookup:',
                            name: 'returntosender.let_id',
                            type: 'datatable',
                            editor: comradeEditor,
                            optionsPair: {
                                value: 'scanned_mail.id',
                            },
                            config: {
                                ajax: 'letterNested.php',
                                buttons: [
                                    { extend: "edit", className: 'btn btn-warning', 
                                        text: '<i class="fa-solid fa-envelope-open-text"></i> View Letter', 
                                        titleAttr: 'View Letter', editor: letterEditor, formTitle: 'View Letter Details',  
                                        formButtons: [
                                        {
                                            text: 'Cancel',
                                            action: function () { this.close(); },
                                            className: 'btn btn-secondary'
                                        }, {
                                            text: 'Update',
                                            action: function () { this.submit(); },
                                            className: 'btn btn-primary'
                                        }
                                    ] 
    
                                    }
    
                                ],
                                columns: [{
                                        title: 'Letter ID',
                                        data: 'scanned_mail.id'
                                    },{
                                        title: 'Postmark',
                                        data: 'scanned_mail.postmark_date'
                                    },{
                                        title: 'Last Name',
                                        data: 'form.LastName'
                                    },{
                                        title: 'First Name',
                                        data: 'form.FirstName'
                                    },{
                                        title: 'DOC #',
                                        data: 'form.PrisonerID'
                                    },{
    
                                        title: 'Printed on',
                                        data: 'scanned_mail.date_printed'
      
                                    }                                
                                ],
                                lengthMenu: [[5,10,20,-1],[5,10,20,"All"]],
                                pageLength: 5,
                                autoWidth: true,
                                select: true                            
                            }                          
                        }, {
                            // label: 'Facility ID:',
                            // name: 'returntosender.return_facility_id',
                            // type: 'select'
                            label: 'Facility Lookup:',
                            name: 'returntosender.return_facility_id',
                            type: 'datatable',
                            editor: comradeEditor,
                            optionsPair: {
                                value: 'PrisonFacilityListing.Facility_ID',
                            },
                            config: {
                                ajax: 'facilityNested.php',
                                buttons: [
    
                                    { extend: "create", className: 'btn btn-success',
                                        text: '<i class="fa-solid fa-tower-observation"></i> New Facility', 
                                        titleAttr: 'Add New Facility', editor: facilityEditor, formTitle: 'Add New Facility' 
                                    },
                                    { extend: "edit", className: 'btn btn-warning', 
                                        text: '<i class="fa-solid fa-tower-observation"></i> Edit Facility', 
                                        titleAttr: 'Edit Facility', editor: facilityEditor, formTitle: 'Edit Facility',  
                                        formButtons: [
                                        {
                                            text: 'Cancel',
                                            action: function () { this.close(); },
                                            className: 'btn btn-secondary'
                                        }, {
                                            text: 'Update',
                                            action: function () { this.submit(); },
                                            className: 'btn btn-primary'
                                        }
                                    ] 
    
                                    }
    
                                ],
                                columns: [{
                                        title: 'Facility Name',
                                        data: 'PrisonFacilityListing.Prison_Name'
                                    },{
                                        title: 'Type',
                                        data: 'PrisonFacilityListing.Facility_Type'
                                    },{
                                        title: 'City',
                                        data: 'PrisonFacilityListing.City'
                                    },{
                                        title: 'State',
                                        data: 'PrisonFacilityListing.State'
                                    },{
                                        title: 'Phone',
                                        data: 'PrisonFacilityListing.Phone_Number'
                                    },{
                                        title: 'Scanning Center',
                                        data: "PrisonFacilityListing.scanning_center", 
                                        render: function (val, type, row) {
                                            return val == 0 ? "No" : "Yes";
                                        }  
                                    }                                
                                ],
                                lengthMenu: [[5,10,20,-1],[5,10,20,"All"]],
                                pageLength: 5,
                                autoWidth: true,
                                select: true                            
                            }                        
                        }, {
                            label: 'Return Postmark:',
                            name: 'returntosender.return_date',
                            type: 'datetime',
                                def: function () { return new Date(); },
                                displayFormat: "M/D/YYYY",
                                wireFormat: "YYYY-MM-DD",
                                fieldInfo: "US style m/d/y format",
                                keyInput: true                           
                        }, {
                            label: 'Return Reason:',
                            name: 'returntosender.return_reason'
                        }, {
                            label: 'How Resolved:',
                            name: 'returntosender.resolve_type'
                        }, {
                            label: 'Date Resolved:',
                            name: 'returntosender.resolve_date',
                            type: 'datetime',
                                def: function () { return new Date(); },
                                displayFormat: "M/D/YYYY",
                                wireFormat: "YYYY-MM-DD",
                                fieldInfo: "US style m/d/y format",
                                keyInput: true                           
                        }, {
                            label: 'Resolved By:',
                            name: 'returntosender.resolved_by'
                        }, {
                            label: 'Notes:',
                            name: 'returntosender.notes',
                            type: 'quill'
                        }, {
                            label: 'Return Letter:',
                            name: 'returntosender.rts_image',
                            type: "upload",
                                display: function ( file_id ) {
                                    return '<img src="'+editor.file( 'rts_scans', file_id ).web_path+'"/>';
                                },
                            clearText: "Clear",
                            noImageText: 'No Letter'                                                                                                                                                                                                                                                                        
                        }
                    ]
                });
    
  • Stacey1134Stacey1134 Posts: 112Questions: 20Answers: 0
    edited January 10

    serverSide scripts

    <!-- comradeNested.php -->
    <?php
    
    session_start();
    // include( "../Editor-PHP/lib/DataTables.php" );  // Editor 2.1.3
    include( "../assets/datatables/lib/DataTables.php" ); //Editor 2.2.2
    
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Options;
    
    Editor::inst( $db, 'form', 'CR_ID' )
        ->fields(
            Field::inst( 'form.CR_ID' )->set( false ),
            Field::inst( 'form.PrisonerID' ),
            Field::inst( 'form.FirstName' ),
            Field::inst( 'form.LastName' ),
            Field::inst( 'form.PrefName' ),     
            Field::inst( 'form.IsAbby' ),
            Field::inst( 'form.FAC_ID' )
                ->options( Options::inst()
                    ->table( 'PrisonFacilityListing' )
                    ->value( 'Facility_ID' )
                    ->label( array('Prison_Name','State' ))
                )
        )
        ->leftJoin( 'PrisonFacilityListing', 'PrisonFacilityListing.Facility_ID', '=', 'form.FAC_ID' )       
        ->process( $_POST )
        ->json();     
    
    <!-- letterNested.php -->
    <?php
    
    session_start();
    // include( "../Editor-PHP/lib/DataTables.php" );  // Editor 2.1.3
    include( "../assets/datatables/lib/DataTables.php" ); //Editor 2.2.2
    
    use
        DataTables\Editor,
        DataTables\Editor\Field;
    
    
    Editor::inst( $db, 'scanned_mail' )
        ->fields(
            Field::inst( 'scanned_mail.id' )->set( false ),
            Field::inst( 'scanned_mail.cr_id' )->set( false ),
            Field::inst( 'form.FirstName' )->set( false ),
            Field::inst( 'form.LastName' )->set( false ),
            Field::inst( 'form.PrisonerID' )->set( false ),
            Field::inst( 'scanned_mail.postmark_date' )->set( false ),
            Field::inst( 'scanned_mail.answered_by' )->set( false ),
            Field::inst( 'scanned_mail.response' )->set( false ),
            Field::inst( 'scanned_mail.resources' )->set( false ),
            Field::inst( 'scanned_mail.scanner' )->set( false ),
            Field::inst( 'scanned_mail.notes' )->set( false ),
            Field::inst( 'scanned_mail.printed_by' )->set( false ),
            Field::inst( 'scanned_mail.date_printed' )->set( false ),
        )
        ->leftJoin( 'form', 'form.CR_ID', '=', 'scanned_mail.cr_id' )    
        ->process( $_POST )
        ->json(); 
    
    <!-- facilityNested.php -->
    <?php
    
    session_start();
    // include( "../Editor-PHP/lib/DataTables.php" );  // Editor 2.1.3
    include( "../assets/datatables/lib/DataTables.php" ); //Editor 2.2.2
    
    use
        DataTables\Editor,
        DataTables\Editor\Field;
    
    Editor::inst( $db, 'PrisonFacilityListing', 'Facility_ID' )
        ->fields(
            Field::inst( 'PrisonFacilityListing.Facility_ID' )->set( false ),
            Field::inst( 'PrisonFacilityListing.Facility_Type' ),
            Field::inst( 'PrisonFacilityListing.Prison_Name' ),
            Field::inst( 'PrisonFacilityListing.City' ),
            Field::inst( 'PrisonFacilityListing.State' ),
            Field::inst( 'PrisonFacilityListing.Phone_Number' ),
            Field::inst( 'PrisonFacilityListing.eOnly' ),
            Field::inst( 'PrisonFacilityListing.Mail_Addr_1' ),
            Field::inst( 'PrisonFacilityListing.Mail_Addr_2' ),
            Field::inst( 'PrisonFacilityListing.Mail_Addr_3' ),
            Field::inst( 'PrisonFacilityListing.Mail_City' ),
            Field::inst( 'PrisonFacilityListing.Mail_State' ),
            Field::inst( 'PrisonFacilityListing.Mail_Zip' ),
            Field::inst( 'PrisonFacilityListing.scanning_center' )
    
        )   
        ->process( $_POST )
        ->json();
    

    Thanks in advance

  • Stacey1134Stacey1134 Posts: 112Questions: 20Answers: 0

    sorry darn thing made me break my code up

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

    I think what is happening is as a result of the editor option for the Facility and the Letter configuration objects. They both have: editor: comradeEditor,. It should be:

    editor: letterEditor,
    

    And

    editor: facilityEditor,
    

    for the facility field.

    What appears to be happening is that the data for the facility is being written into the Comrade field, thus when you click edit, it can't find the data.

    Hopefully, changing that will fix it. Let me know how you get on with it.

    Allan

  • Stacey1134Stacey1134 Posts: 112Questions: 20Answers: 0

    Crap. I swear I thought I had fixed that. Thanks, sorry for taking up your time. Appreciate the help.

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

    No worries. An easy one to miss!

    Allan

Sign In or Register to comment.