How do refresh the Editor after Insert/Edit/Remove (From Generator's code)

How do refresh the Editor after Insert/Edit/Remove (From Generator's code)

simonngsimonng Posts: 1Questions: 1Answers: 0

I have generated the Ediitor code and made some updates.
After any insert, edit, or removal of the form data, the page isn't updated when returned.
I tried various methods as shown below.
I can only get it updated via a manual button.

*
 * Editor client script for DB table gf_fav
 * Created by http://editor.datatables.net/generator
 */

(function($){

$(document).ready(function() {
    var editor = new DataTable.Editor( {
        ajax: 'php/table.gf_fav.php',
        table: '#gf_fav',
        fields: [
            {
                "type": "readonly",
                "label": "Member No:",
                "name": "memberid",
                "def" : $("#memberid").val()
            },
            {
                "label": "Buddy No:",
                "name": "gf_mid"
            },
            {
                "label": "Buddy name:",
                "name": "gf_name"
            },
            {
                "label": "Category:",
                "name": "gf_cat",
                "type": "select",
                "options": [
                    { label:"GG", value:"GG" },
                    { label:"GS", value:"GS" },
                    { label:"Customer Union", value:"CU" },
                    { label:"Guest", value:"GU" }
                ]
            },
            {
                "label": "Handicap:",
                "name": "gf_hcap"
            }
        ]
    } );

    var table = new DataTable('#gf_fav', {
        dom: 'Bfrtip',
        ajax: {
            'url' : 'php/table.gf_fav.php',
            'data' : {
                'memberid' : $("#memberid").val()
            }
        },
        columns: [
            {
                "data": "memberid"
            },
            {
                "data": "gf_mid"
            },
            {
                "data": "gf_name"
            },
            {
                "data": "gf_cat"
            },
            {
                "data": "gf_hcap"
            }
        ],
        select: true,
        lengthChange: false,
        buttons: [
            { extend: 'create', editor: editor },
            { extend: 'edit',   editor: editor },
            { extend: 'remove', editor: editor },
            { text: 'Refresh', action: function ( e, dt, node, config ) {
                             dt.ajax.reload();
                        } }
        ]
    } );
editor.on( 'postCreate',   function () { table.ajax.reload();    } );
editor.on( 'postEdit',  function () { table.ajax.reload(); alert('Edited!');   } );
editor.on( 'postRemove', function () { table.ajax.reload();  } );

setInterval( function () {
    table.ajax.reload();
}, 10000 );

} );


}(jQuery));

How can I have the page auto-refresh after insert/edit/delete a record? (From database)

Answers

  • kthorngrenkthorngren Posts: 20,591Questions: 26Answers: 4,823

    Are you using Datatables supplied server scripts?

    The client server data docs describe the expected response from the server. This will allow the table to be updated automatically. You can use the browser's network inspector tool to see the response from any Editor request (create, edit or delete).

    Kevin

Sign In or Register to comment.