DataTables Client Side Does Not Refresh After Updating Row

DataTables Client Side Does Not Refresh After Updating Row

ronovarronovar Posts: 6Questions: 2Answers: 0

I im using DataTables v10 and defined:

      $(document).ready(function() {
        $("#datatable").DataTable({
            language: {
                paginate: {
                    previous: "<i class='mdi mdi-chevron-left'>",
                    next: "<i class='mdi mdi-chevron-right'>"
                }
            },
            drawCallback: function() {
                $(".dataTables_paginate > .pagination").addClass("pagination-rounded");
            },
            responsive: false,
            aaSorting: [
                [ 1, 'desc' ]
            ]
        });
        $("#datatable").css("width", "100%");

        $('#datatable').on('click', 'i.text-success.fas.fa-circle, i.text-danger.fas.fa-circle', function(e) {
        var id       = $(this).closest('tr').find('td:eq(1)').text(),
            payed    = $(this).closest('tr').attr('payed'),
            reseller = $(this).closest('tr').find('td:eq(2)').text(),
            msg      = '';

        if (payed == 1) { msg = 'NOT '; }
        if (confirm('Are You Sure That "' + reseller + '" Have ' + msg + 'Payed?') == true) {
            e.preventDefault();
            $.ajax({
                url: './calculations-api.php?type=1&id='+id,
                success: function(response){
                    $('#datatable').DataTable().draw(false);
                    alert(response);
                }
            });
        } else {
            return;
        }
    });
 });

calculations-api.php return only text message like "Success Payed!" so as you can see i im using client side DataTables...my problem is when i click to update data...data is updated on server side, returned message from calculations-api.php "Success Payed!" and DataTables is not refreshed...so i try this code to refresh DataTable after message is returned from server:

$('#datatable').DataTable().draw(false);
But table is not refreshed...so is there another solution? Reloading page is not solution, only DataTables.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Are you using Editor to update? Or just your ajax() call? You're doing a draw() but I can't see where any new data is being changed in the table.

    Colin

  • ronovarronovar Posts: 6Questions: 2Answers: 0

    Yes...i manually update clicked row and calling draw API now it works..thanks for pointing me out for problem.

  • JuJoGuAlJuJoGuAl Posts: 32Questions: 2Answers: 0

    have the same issue, i have Editor, and C# (server) asp.net (Client) when i submit a form (with the data updated by editor) i can't see the new values only get the old one...

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    @JuJoGuAl If you refresh the page, does the new value get displayed?

    Colin

  • JuJoGuAlJuJoGuAl Posts: 32Questions: 2Answers: 0

    @colin not, only the Old one, "/

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin

    @JuJoGuAl - Can you give me a link to your page please? Not seeing the data updated by Editor suggests the server isn't returning the data expected by Editor. Can you show me the JSON response from the server for the Ajax submit of the updated data?

    Thanks,
    Allan

This discussion has been closed.