Redraw table on submit form with ajax.

Redraw table on submit form with ajax.

neurofunkneurofunk Posts: 14Questions: 5Answers: 1
edited July 2015 in Free community support

Hello there.

Based od this example:
https://datatables.net/examples/server_side/row_details.html
I wrote custom editor for a datatable (without native editor extension), becouse I'm a newbie programmer, and I wanna learn something.

In first version, the form is sending "normally":

<form action="editor.php">
</form>

then editor.php making queries into mysql and do redirect back to the index.php.

Now. I wanna make some modernization, and I send form via ajax:

$('form').submit(function (e){
 e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'editor.php',
            contentType: "charset=utf-8",  
            data: new FormData(this),
            processData: false,
        }).done(function(data){
           alert( "Done" )
        }).fail(function() {
            alert( "Fail." );             
        });
        return false;
})

Database updates correctly, but I have a problem: How can I do redraw datatable when the script is done?

Answers

  • neurofunkneurofunk Posts: 14Questions: 5Answers: 1
    edited July 2015

    Ok. I'm embarassed. It's simple like fking ;)

    $('form').submit(function (e){
     e.preventDefault();
            $.ajax({
                type: 'POST',
                url: 'editor.php',
                contentType: "charset=utf-8", 
                data: new FormData(this),
                processData: false,
            }).done(function(data){
                dataTable.draw()          // <-- !!
            }).fail(function() {
                alert( "Fail." );            
            });
            $('.editor').hide()
            return false;
    })
    
This discussion has been closed.