I'm having an issue with inline editor. Am I supposed to use the PHP server-side processing?

I'm having an issue with inline editor. Am I supposed to use the PHP server-side processing?

GlueData AccountsGlueData Accounts Posts: 5Questions: 2Answers: 0
edited September 2020 in Free community support

I don't have a test case to link to.

Below is my code:

$scope.title = "Users";

$(document).ready(function(){

    var editor;

    $('.sidenav').sidenav();
    $('select').formSelect();
    $('.dropdown-trigger').dropdown();

    $('#users').on( 'click', 'tbody tr td', function (e) {
        editor.inline( this );
    } );


    var init = function () {
        $.ajax({
            url:"./php/getUsers.php", //the page containing php script
            method: "GET", //request type
            error: function() {
                $('#info').html('<p>An error has occurred</p>');
            },
            success:function(result){
                $scope.data = JSON.parse(result);
                console.log($scope.data);

                editor = new $.fn.dataTable.Editor( {
                    ajax: "./php/updateUser.php",
                    table: "#users",
                    idSrc: "USER_SK",
                    fields: [ 

                        {
                            label: "User Sk:",
                            name: "USER_SK"
                        }, {
                            label: "User Nk:",
                            name: "USER_NK"
                        }, {
                            label: "User Alias:",
                            name: "USER_ALIAS"
                        }, {
                            label: "User Name:",
                            name: "USER_NAME"
                        }, {
                            label: "User Surname:",
                            name: "USER_SURNAME"
                        }, {
                            label: "User Org Fk:",
                            name: "USER_ORG_FK"
                        }, {
                            label: "User Type Fk:",
                            name: "USER_TYPE_FK"
                        }, {
                            label: "Update Date:",
                            name: "UPDATE_DATE"
                        }, {
                            label: "Create Date:",
                            name: "CREATE_DATE"
                        }, {
                            label: "User Status:",
                            name: "USER_STATUS"
                        }, {
                            label: "Failed Login Counter:",
                            name: "FAILED_LOGIN_COUNTER"
                        }
                    ]
                } );

                var table = $('#users').DataTable( {
                    data: $scope.data,
                    dom: 'Bfrtip',
                    columns: [
                        {
                            data: "USER_SK"
                        },
                        {
                            data: "USER_NK"
                        },
                        {
                            data: "USER_ALIAS"
                        }, 
                        {
                            data: "USER_NAME"
                        },
                        {
                            data: "USER_SURNAME"
                        },
                        {
                            data: "USER_ORG_FK"
                        },
                        {
                            data: "USER_TYPE_FK"
                        },
                        {
                            data: "UPDATE_DATE"
                        },
                        {
                            data: "CREATE_DATE"
                        },
                        {
                            data: "USER_STATUS"
                        },
                        {
                            data: "FAILED_LOGIN_COUNTER"
                        },
                        // etc
                    ],
                    select: true,
                    buttons: [
                        { extend: "create", editor: editor },
                        {
                            extend: 'selected',
                            text:   'Edit',
                            action: function () {
                                var indexes = table.rows( {selected: true} ).indexes();

                                editor.edit( indexes, {
                                    title: 'Edit',
                                    buttons: indexes.length === 1 ?
                                        backNext :
                                        'Save'
                                } );
                            }
                        },
                        { extend: "remove", editor: editor },
                        {
                            extend: 'collection',
                            text: 'Export',
                            buttons: [
                                'copy',
                                'excel',
                                'csv',
                                'pdf',
                                'print'
                            ]
                        }
                    ],
                    formOptions: {
                        inline: {
                            onBlur: 'submit',
                            submit: 'allIfChanged'
                        }
                    },
                    editOnFocus: true,
                    lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]]
                } );
            }
        });
    }

    var backNext = [
        {
            text: "&lt;",
            action: function (e) {
                // On submit, find the currently selected row and select the previous one
                this.submit( function () {
                    var indexes = table.rows( {search: 'applied'} ).indexes();
                    var currentIndex = table.row( {selected: true} ).index();
                    var currentPosition = indexes.indexOf( currentIndex );

                    if ( currentPosition > 0 ) {
                        table.row( currentIndex ).deselect();
                        table.row( indexes[ currentPosition-1 ] ).select();
                    }

                    // Trigger editing through the button
                    table.button( 1 ).trigger();
                }, null, null, false );
            }
        },
        'Save',
        {
            text: "&gt;",
            action: function (e) {
                // On submit, find the currently selected row and select the next one
                this.submit( function () {
                    var indexes = table.rows( {search: 'applied'} ).indexes();
                    var currentIndex = table.row( {selected: true} ).index();
                    var currentPosition = indexes.indexOf( currentIndex );

                    if ( currentPosition < indexes.length-1 ) {
                        table.row( currentIndex ).deselect();
                        table.row( indexes[ currentPosition+1 ] ).select();
                    }

                    // Trigger editing through the button
                    table.button( 1 ).trigger();
                }, null, null, false );
            }
        }
    ];



    init();

On submit of inline edit, I get "System error occurred". However my data is updated in my database, I can't seem to find the solution to it.

To my understanding the data should instantly be updated without having to refresh the page.

Answers

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited September 2020

    I wonder what issue you're having.
    EDIT: You have edited your post since I posted.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Could you post the JSON being sent to the server on the submit, and the response from the server, please,

    Colin

  • GlueData AccountsGlueData Accounts Posts: 5Questions: 2Answers: 0

    Is this sufficient information?

    I failed to note that this error occurs when I try create, edit and delete any data.

    All the actions do the right thing in the database, but show 'system error has occurred' on button click.

  • GlueData AccountsGlueData Accounts Posts: 5Questions: 2Answers: 0
    edited September 2020

    Here is my PHP file

  • allanallan Posts: 63,180Questions: 1Answers: 10,411 Site admin

    Is this sufficient information?

    Almost! Can you click on the "Response" tab (which is just above the "General" at the top of the screenshot) and then show me that? The error message you are seeing means that there is invalid JSON being returned from the server - hopefully it shows an error message inease.

    Allan

This discussion has been closed.