无论什么时候我插入我松散我的数据表结构属性几毫秒

时间:2021-09-29 14:25:10

gif image for understanding

用于理解的gif图像

无论什么时候我插入我松散我的数据表结构属性几毫秒

I am facing the problem when I insert any record in datatable I have uploaded gif image for understaing purpose. This is my display function.

我在数据表中插入任何记录时遇到问题我已经上传了gif图像用于理解目的。这是我的显示功能。

function display_record() {
    table = $('#tbl_data').DataTable({

        "data": arr12,
        "iDisplayLength": 10,
        "dom": 'lfrtp',
        "pagingType": "first_last_numbers",
        "bRetrieve": true,
        "aoColumnDefs": [{
                "aTargets": [0],
                "sTitle": "Id",
                "bSortable": true,
                "class": "Id",
                "sWidth": "80px",


            },


            {
                "aTargets": [1],
                "sTitle": "name",
                "bSortable": true,
                "sWidth": "100px"
            },
            {
                "aTargets": [2],
                "sTitle": "gender",
                "bSortable": true,
                "sWidth": "100px"
            },
            {
                "aTargets": [3],
                "sTitle": "pincode",
                "bSortable": true,
                "bSearchable": false,
                "sWidth": "80px",

            },
            {
                "aTargets": [4],
                "sTitle": "city",
                "bSortable": true,
                "bSearchable": false,
                "sWidth": "80px",

            },
            {
                "aTargets": [5],
                "sTitle": "Action",
                "bSortable": true,
                "bSearchable": false,
                "sWidth": "80px",
                "render": function(data, type, row) {
                    var returnHTML = CreateDataHTML(data);
                    return returnHTML;
                }

            }

        ]
    });
}

function CreateDataHTML(data) {
    return "<button type='button' class='delete glyphicon glyphicon-remove' id=" + data + " data-toggle='tooltip' title='delete' style='background-color:#E74C3C;color:white;'></button></td></tr>";
}

This is insert code.

这是插入代码。

$("#insert").on("click", function(e) {

$.ajax({
    type: "POST",
    url: "Train8.aspx/addNewEmp",
    data: JSON.stringify({
        Id: Id,
        name: name,
        gender: gender,
        pincode: pincode,
        City: City
    }),
    contentType: "application/json;charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    error: OnErrorCall
});

function OnSuccess(response) {
    var result = response.d;
    if (result == "success") {
        $("#msg").html("New record addded successfully  :)").css("color", "green");
        display_record();
        table.destroy();


    }

}

function OnErrorCall(response) {
    $("#msg").html(response.responseText);
}

});

});

This is insert code I am using table.destroy();

这是我使用table.destroy()的插入代码;

1 个解决方案

#1


0  

You are destroying and re initializing your table, that is why.

你正在摧毁并重新初始化你的桌子,这就是原因。

You can prevent this by using ajax API's:
ajax.reload()
ajax.url().reload()
ajax.url()

你可以通过使用ajax API来防止这种情况:ajax.reload()ajax.url()。reload()ajax.url()

Reference: https://datatables.net/reference/api/

参考:https://datatables.net/reference/api/

#1


0  

You are destroying and re initializing your table, that is why.

你正在摧毁并重新初始化你的桌子,这就是原因。

You can prevent this by using ajax API's:
ajax.reload()
ajax.url().reload()
ajax.url()

你可以通过使用ajax API来防止这种情况:ajax.reload()ajax.url()。reload()ajax.url()

Reference: https://datatables.net/reference/api/

参考:https://datatables.net/reference/api/