Edit window does not show values

Edit window does not show values

VJLumban11VJLumban11 Posts: 6Questions: 1Answers: 0

Edit window does not show values but it saves to database.

This question has an accepted answers - jump to answer

Answers

  • tangerinetangerine Posts: 3,348Questions: 36Answers: 394

    I don't understand. Are you saying nothing appears when you type into the form's input fields? Please give a better explanation.

  • VJLumban11VJLumban11 Posts: 6Questions: 1Answers: 0

    Values of the row does not show up in the edit form (by clicking edit). But when you type in the field, it updates in the database

  • kthorngrenkthorngren Posts: 20,269Questions: 26Answers: 4,765

    Something doesn't look right. In the background it looks like you have a row selected but the table info states "Showing 0 to 0....". Can you provide a link to your code showing the issue?

    If not maybe you can start with posting your Javascript code.

    Kevin

  • VJLumban11VJLumban11 Posts: 6Questions: 1Answers: 0
    edited July 2017
    <script type="text/javascript" language="javascript" class="init">
        
    
        var editor; // use a global for the submit and return data rendering in the examples
    
        $(document).ready(function() {
            editor = new $.fn.dataTable.Editor({        
                "ajax": "../php/staff.php",
                "table": "#example",
                "template": '#customForm',
                "idSrc": 'hs_rowID',
                "fields": [{
                    label: "Last Name:",
                    name: "hs_lastName",
                    attr: {
                        placeholder: 'Last Name'
                    },
                }, {
                    label: "First Name:",
                    name: "hs_firstName",
                    attr: {
                        placeholder: 'First Name'
                    },
                }, {
                    label: "Middle Initial:",
                    name: "hs_mI",
                    attr: {
                        placeholder: 'Middle Initial'
                    },
                }, {
                    label: "House/Bldg No.:",
                    name: "hs_houseBldgNo",
                    attr: {
                        placeholder: "House/Bldg No."
                    },
                }, {
                    label: "Street:",
                    name: "hs_street",
                    attr: {
                        placeholder: "Street"
                    },
                }, {
                    label: "Barangay:",
                    name: "hs_barangay",
                    attr: {
                        placeholder: "Barangay"
                    },
                }, {
                    label: "Municipality/City:",
                    name: "hs_cityMunicipality",
                    attr: {
                        placeholder: "Municipality/City"
                    },
                }, {
                    label: "Province:",
                    name: "hs_province",
                    attr: {
                        placeholder: "Province"
                    },
                }, {
                    label: "Country:",
                    name: "hs_country",
                    attr: {
                        placeholder: "Country"
                    },
                }, {
                    label: "Zip Code:",
                    name: "hs_zipCode",
                    attr: {
                        placeholder: "Zip Code"
                    },
                }, {
                    label: "Mobile Number:",
                    name: "hs_mobileNumber",
                    attr: {
                        placeholder: "Mobile Number"
                    },
                }, {
                    label: "Email Address:",
                    name: "hs_email",
                    attr: {
                        placeholder: "Email Address"
                    },
                }, {
                    label: "Preferred Communication:",
                    name: "hs_prefcomms",
                    type: "radio",
                    options: [{
                            label: "Mobile Number",
                            value: "Mobile Number"
                        },
                        {
                            label: "Landline Number",
                            value: "Landline Number"
                        },
                        {
                            label: "Email Address",
                            value: "Email Address"
                        }
                    ],
                    def: 0
                }, {
                    label: "VIP? ",
                    name: "hs_guestVIP",
                    type: "radio",
                    options: [{
                            label: "Yes",
                            value: "Y"
                        },
                        {
                            label: "No",
                            value: "N"
                        }
                    ],
                    def: 0
                }, {
                    label: "Corporate Account? ",
                    name: "hs_corpID",
                    type: "radio",
                    options: [{
                            label: "Yes",
                            value: "Y"
                        },
                        {
                            label: "No",
                            value: "N"
                        }
                    ],
                    def: 0
                }, {
                    label: "Travel Agency:",
                    name: "hs_agentID",
                    type: "select",
                    placeholder: "Select a Value",
                    options: [{
                            label: "Sunlife",
                            value: "1"
                        },
                        {
                            label: "Pru Life UK",
                            value: "2"
                        },
                        {
                            label: "Insular Life",
                            value: "3"
                        },
                        {
                            label: "Manulife",
                            value: "4"
                        },
                        {
                            label: "AXA",
                            value: "5"
                        }
                    ]
                }, {
                    label: "IATA:",
                    name: "hs_IATAID",
                    attr: {
                        placeholder: "IATA"
                    },
                }, {
                    label: "Account:",
                    name: "hs_accountID",
                    attr: {
                        placeholder: "Account"
                    },
                }, {
                    label: "Membership:",
                    name: "hs_memCode",
                    attr: {
                        placeholder: "Membership"
                    },
                }]
            });
    
            $('#example').DataTable({
                serverSide: true,
                processing: true,
                dom: "Bfrtip",
                "ajax": {
                    "method": "POST",
                    "url": "ajaxRequest.php",
                    "data": {
                        getfunctionName: "getAllGuest"
                    },
                    "dataSrc": function(json) {
                        var return_data = new Array();
                        for (var i = 0; i < json.length; i++) {
                            return_data.push({
                                'hs_rowID': json[i].hs_rowID,
                                'lastName': json[i].hs_lastName,
                                'firstName': json[i].hs_firstName,
                                'mI': json[i].hs_mI,
                                'houseBldgNo': json[i].hs_houseBldgNo,
                                'street': json[i].hs_street,
                                'barangay': json[i].hs_barangay,
                                'cityMunicipality': json[i].hs_cityMunicipality,
                                'province': json[i].hs_province,
                                'country': json[i].hs_country,
                                'zipCode': json[i].hs_zipCode
                            })
                        }
                        return return_data;
                    }
                },
                columns: [{
                        data: "hs_rowID"
                    },
                    {
                        data: null,
                        render: function(data, type, row) {
                            // Combine the first and last names into a single table field
                            return row.lastName + ", " + row.firstName + " " + row.mI;
                        }
                    },
                    {
                        data: null,
                        render: function(data, type, row) {
                            // Combine the first and last names into a single table field
                            return row.houseBldgNo + " " + row.street + " Brgy. " + row.barangay + ", " + row.cityMunicipality + ", " + row.province + ", " + row.country + " " + row.zipCode;
                        }
                    }
                ],
                select: true,
                buttons: [{
                        extend: "create",
                        editor: editor
                    },
                    {
                        extend: "edit",
                        editor: editor
                    },
                    {
                        extend: "remove",
                        editor: editor
                    }
                ]
            });
        });
        
    </script>
    
  • VJLumban11VJLumban11 Posts: 6Questions: 1Answers: 0
    <?php
    
    /*
     * Example PHP implementation used for the index.html example
     */
    
    // DataTables PHP library
    include( "../../php/DataTables.php" );
    
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'guests', 'hs_rowID' )
        ->fields(
            Field::inst( 'hs_lastName' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_firstName' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_mI' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_houseBldgNo' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_street' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_barangay' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_cityMunicipality' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_province' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_country' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_zipCode' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_mobileNumber' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_email' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_prefcomms' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_guestVIP' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_corpID' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_agentID' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_IATAID' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_accountID' )->validator( 'Validate::notEmpty' ),
            Field::inst( 'hs_memCode' )->validator( 'Validate::notEmpty' )
        )
        ->process( $_POST )
        ->json();
    
    
    // On 'read' remove the DT_RowId property so we can see fully how the `idSrc`
    // option works on the client-side.
    if ( Editor::action( $_POST ) === Editor::ACTION_READ ) {
        for ( $i=0, $ien=count($out['data']) ; $i<$ien ; $i++ ) {
            unset( $out['data'][$i]['DT_RowId'] );
        }
    }
    
    if(isset($out)){ 
    // Send it back to the client
    echo json_encode( $out );
    }
    
    ?>
    
    
  • VJLumban11VJLumban11 Posts: 6Questions: 1Answers: 0

    Hi kthorngren,

    I already fixed the error which states "Showing 0 to 0....". But the values still doesn't show up.

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    Can you remove the ajax.dataSrc function please. You shouldn't need that when using the Editor PHP libraries and I think it will be doing more harm than good when using server-side processing.

    But the values still doesn't show up.

    Do you mean that the edit modal shows, but there are no values in the inputs? Could you link to the page showing the issue so I can help to debug it please?

    Thanks,
    Allan

  • VJLumban11VJLumban11 Posts: 6Questions: 1Answers: 0

    Hi Allan.

    I removed the ajax.dataSrc function and changed the way of populating my datatable. Now, its working.

    Thanks,
    Van

This discussion has been closed.