Datatable refresh after insert

Datatable refresh after insert

classic12classic12 Posts: 228Questions: 60Answers: 4
edited November 2017 in Editor

I am using the standard buttons.

        buttons: [
            { extend: "create", editor: editorQuotes },
            { extend: "edit",   editor: editorQuotes },
            { extend: "remove", editor: editorQuotes }
        ]
editorQuotes.on( 'create', function ( e, json, data ) {
    alert( 'New row added' );
} );

I am able to edit / add /remove.

But the datatable does not refresh when I insert add a new row.

Do I have to manualy call it ?

The create event above is not called.

Cheers

Steve Warby

Answers

  • allanallan Posts: 61,885Questions: 1Answers: 10,140 Site admin

    Does your server-side script return JSON data with the newly added row in it. There is an example in the documentation.

    Allan

  • classic12classic12 Posts: 228Questions: 60Answers: 4

    Hi Allan,
    On the customer table I am using this PHP

    include( "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, 'customers' , 'custID')
        ->fields(
            Field::inst( 'customers.custID' ),
            Field::inst( 'customers.companyName' ),
            Field::inst( 'customers.address1' ),
            Field::inst( 'customers.address2' ),
            Field::inst( 'customers.address3' ),
            Field::inst( 'customers.Post_Code' ),
            Field::inst( 'customers.Mobile' ),
            Field::inst( 'customers.Telephone' ),
            
            Field::inst( 'contacts.custID' ),
            Field::inst( 'contacts.FirstName' )
                )
    
        ->leftJoin( 'contacts', 'customers.custID', '=', 'contacts.custID' )    
        ->process( $_POST )
        ->json();   
    

    The insert works okay.

    How do I get the datatable to just show the inserted row without refreshing the whole datatable.

    Cheers

    Steve Warby

  • allanallan Posts: 61,885Questions: 1Answers: 10,140 Site admin

    With that code it would only refresh the whole DataTable if you are using serverSide. Are you? If not, I don't know why it would be refreshing the whole data set unless there is some code somewhere calling ajax.reload()?

    Allan

This discussion has been closed.