How can i edit or delete the data privious exist in the database?

How can i edit or delete the data privious exist in the database?

Daniel WangDDaniel WangD Posts: 3Questions: 0Answers: 0

The base example only can delete data that you new,you can't delete the previous data

Replies

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

    Hi @'daniel wangD' ,

    Is this an Editor example? Can you link to it, please? Are you asking for transaction logging, where you can go back and edit previous edits? If so, yes, you are correct, that isn't supported.

    Cheers,

    Colin

  • Daniel WangDDaniel WangD Posts: 3Questions: 0Answers: 0
    edited July 2019

    @colin
    this is my code ,i am a new coder;
    I write like this,

        public function getAllUser()
        {
    
    
            $rst = $this->editordb->select('user');
            echo json_encode($rst->fetchAll());
    ~~~~
    
        }
    
        public function editUser(){
            Editor::inst( $this->editordb, 'user' ,'UserId')
                ->fields(
    //                Field::inst('UserId'),
                    Field::inst( 'Name' )
                        ->validator( Validate::notEmpty( ValidateOptions::inst()
                            ->message( 'A first name is required' )
                        ) ),
                    Field::inst( 'Password' )
                        ->validator( Validate::notEmpty( ValidateOptions::inst()
                            ->message( 'A last name is required' )
                        ) ),
                    Field::inst( 'Admin' )->validator( Validate::numeric() )
                        ->setFormatter( Format::ifEmpty(null) ),
                    Field::inst( 'TrieveQuestion' ),
                    Field::inst( 'TrieveAnswer' )
    //                Filed::inst('UserId')
                )
                ->process( $_POST )
                ->json();
    }
    
    
    
                   <script type="text/javascript">
                        var editor; // use a global for the submit and return data rendering in the examples
    
                        $(document).ready(function() {
                            editor = new $.fn.dataTable.Editor( {
                                table: "#example",
                                // type: 'post',
                                ajax : "/UserManagement/user_manage/editUser",
                                // ajax: {
                                //     create: {
                                //         type: 'POST',
                                //         url:  'UserManagement/user_manage/editUser'
                                //     },
                                //     edit: {
                                //         type: 'POST',
                                //         url:  'UserManagement/user_manage/editUser'
                                //     },
                                //     remove: {
                                //         type: 'POST',
                                //         url:  'UserManagement/user_manage/editUser'
                                //     }
                                // },
    
    
    
    
                                fields: [ {
                                    label: "Name:",
                                    name: "Name"
                                }, {
                                    label: "Password:",
                                    name: "Password"
                                }, {
                                    label: "Admin:",
                                    name: "Admin"
                                }, {
                                    label: "TrieveQuestion:",
                                    name: "TrieveQuestion"
                                }, {
                                    label: "TrieveAnswer:",
                                    name: "TrieveAnswer"
                                }
                                ]
                            } );
    
    
    
    
                            var table = $('#example').DataTable( {
                                // lengthChange: false,
                                lengthChange: false,
                                "ajax":{
                                    "url" : "UserManagement/user_manage/getAllUser",
                                    dataSrc: ''
                                },
                                columnDefs: [
                                    {
                                        "targets": 0,
                                        "visible": false,
                                    }
    
    
                                ],
    
    
    
                                "columns": [
                                    { data: "UserId",
                                     sDefaultContent : "NULL"
                                    },
                                    { data: "Name"},
                                    { data: "Icon",
                                        sDefaultContent : ""
                                    },
                                    { data: "Password" },
                                    { data: "Admin" },
                                    { data: "TrieveQuestion"},
                                    { data: "TrieveAnswer"}
                                ],
                                select: true
                                // buttons: [
                                //     { extend: "create", editor: editor },
                                //     { extend: "edit",   editor: editor },
                                //     { extend: "remove", editor: editor }
                            } );
    
                            // Display the buttons
                            new $.fn.dataTable.Buttons( table, [
                                { extend: "create", editor: editor },
                                { extend: "edit",   editor: editor },
                                // { extend: "remove", editor: editor }
    
                                {
                                    extend: "selected",
                                    text: 'Delete',
                                    action: function ( e, dt, node, config ) {
                                        var rows = table.rows( {selected: true} ).indexes();
    
                                        editor
                                            .hide( editor.fields() )
                                            .one( 'close', function () {
                                                setTimeout( function () { // Wait for animation
                                                    editor.show( editor.fields() );
                                                }, 500 );
                                            } )
                                            .edit( rows, {
                                                title: 'Delete',
                                                message: rows.length === 1 ?
                                                    'Are you sure you wish to delete this row?' :
                                                    'Are you sure you wish to delete these '+rows.length+' rows',
                                                buttons: 'Delete'
                                            } )
                                            .val( 'users.removed_date', (new Date()).toISOString().split('T')[0] );
                                    }
                                }
    
                            ] );
    
                            table.buttons().container()
                                .appendTo( $('.col-md-6:eq(0)', table.table().container() ) );
    
    
                            $('#example').on( 'click', 'tbody td:not(:first-child)', function (e) {
                                editor.inline( this );
                            } );
    
                            // $('#example').on( 'click', 'tbody tr', function (e) {
                            //     table.row( this ).delete();
                            // } );
    
                        } );
                    </script>
    

    I mean i can't delete the userdata i create prevoius,for example i create yesterday,but it can display in the table,but when i click the 'delete' button,nothing happen
    when i create a new item and then i don't close the site,i can delete it .

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • Daniel WangDDaniel WangD Posts: 3Questions: 0Answers: 0

    i use the default // { extend: "remove", editor: editor } before
    @colin

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

    Hi @'Daniel WangD' ,

    It sounds like the new row may not be making it into the database - can you confirm that it is being stored? Are you seeing any errors on the client or from the server script?

    Cheers,

    Colin

This discussion has been closed.