HOW TO UPDATE , LOAD OR REFRESH DATATABLES AFTER SUBMIT DATA USING ADD BUTTON

HOW TO UPDATE , LOAD OR REFRESH DATATABLES AFTER SUBMIT DATA USING ADD BUTTON

YudistiraYudistira Posts: 10Questions: 4Answers: 0

How I can to update, load or refresh DataTables after submit data using add button and retrieve the new data on DataTables.

Answers

  • YudistiraYudistira Posts: 10Questions: 4Answers: 0

    Below is my code

    <script>
    $( document ).ready(function() {
            var oTable = $('#t_table').dataTable({
            "bProcessing": true,
            "deferRender": true,
            "scrollY": 260,
            "pagingType": "full_numbers",
            "sAjaxSource": "load_data.php",
            "aoColumnDefs" : [ {
                          "bSortable" : false,
                          "aTargets" : [ 0,1,2,3 ]
                      } ],
            });
            });
            
    $(".btn_submit").click(function() {
    var CustID = $("#CustID").val();
    var CustName = $("#CustName").val();
    var Region = $("#Region").val();
    
    if(CustID=='')
    {
    alert("Enter some text..");
    $("#CustID").focus();
    }
    else
    {
    $("#flash").show();
    $("#flash").fadeIn(400).html('<span class="fa fa-spinner fa-spin"></span>');
    $.ajax({
    type: "POST",
    url: "insert.php",
    data: {CustID: CustID, CustName: CustName, Region: Region},
    cache: true,
    success: function(html){
        $("#show").after(html);
        document.getElementById('CustID').value='';
        document.getElementById('CustName').value='';
        document.getElementById('Region').value=''; 
        $("#flash").hide();
        $("#CustID").focus();
    }  
    });
    }
    return false;
    }); 
    });
    </script>
    
This discussion has been closed.