如何重新启动使用JQuery中的追加创建的DataTable?

时间:2022-09-17 11:42:05

I have an issue at restarting my datatable, when I fill my datatable according a web service results, and it fills correctly but at the moment to make a research by clicking the (Search Button) again the datatable contains the old header and it shows the results but the function does not include the results into the DataTable and it shows 1 to 1 of 1 entries, which is correspondence to old searching.

我在重新启动数据表时遇到问题,当我根据Web服务结果填充我的数据表时,它正确填充但是此时通过再次单击(搜索按钮)进行研究,数据表包含旧标题并显示结果但该函数不包括DataTable中的结果,它显示1个条目中的1到1,这与旧搜索相对应。

This is my JavaScript:

这是我的JavaScript:

$.ajax({
                type: 'POST',
                url: '/enrollment.asmx/MethodSearch',
                data: "{ 'esiidVal': " + $("#esiID").val() + "}",
                contentType: "application/json; utf-8",
                dataType: "json",
                success: function (data) {
                    $("#loadingDiv").hide();

                    //$("#data").append("<table id='tbSearch' class='table table-hover display'><thead><tr><th>City</th><th>Zip</th><th>Address</th><th>State</th><th>Location ID</th></tr></thead><tbody><tr id='" + data.d.City + data.d.Zip + data.d.Adds + "'><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/city'>" + data.d.City + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/zip'>" + data.d.Zip + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/adds'>" + data.d.Adds + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/state'>" + data.d.State + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/location'>" + data.d.SNumer + "</td></tr></tbody></table>");
                    $("#db").append("<thead><tr><th>Selection</th><th>City</th><th>Zip</th><th>Address</th><th>State</th><th>ESIID</th><th>Utility</th></tr></thead><tbody><tr id='" + data.d.City + data.d.Zip + data.d.Adds + "'><td><input type='checkbox' name='userinformation' value='#'></td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/city'>" + data.d.City + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/zip'>" + data.d.Zip + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/adds'>" + data.d.Adds + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/state'>" + data.d.State + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/location'>" + data.d.SNumer + "</td><td id='" + data.d.City + data.d.Zip + data.d.Adds + "/utility'>" + data.d.Utility + "</td></tr></tbody>");
                    //var html = "<thead><tr><th>City</th><th>Zip</th><th>Address</th><th>State</th><th>ESIID</th><th>Utility</th></tr></thead><tbody>";
                    $('#db').DataTable();

                    $('#db').after($("checkbox").addClass('checkbox-primary'));


                },
                error: function (e) {
                    alert(JSON.stringify(e));
                    $("#divResult").html("Something Wrong.");
                }
            });

如何重新启动使用JQuery中的追加创建的DataTable?

I tried destroy(), didn't work, I also tried clean() didn't work. I have weeks facing this issue. Can somebody help me with my issue?

我试过destroy(),没用,我也试过干净()没用。我有几周时间面对这个问题。有人可以帮我解决我的问题吗?

Thanks in advance.

提前致谢。

2 个解决方案

#1


0  

table.draw() should do the trick. Make the call after appending rows.

table.draw()应该做的伎俩。追加行后进行调用。

#2


0  

Try this Code :

试试这个代码:

$('#dt table').dataTable().fnDestroy();<br/>
var tr = $("#td" + id).parent().remove();<br/>
$('#dt table').dataTable();

#1


0  

table.draw() should do the trick. Make the call after appending rows.

table.draw()应该做的伎俩。追加行后进行调用。

#2


0  

Try this Code :

试试这个代码:

$('#dt table').dataTable().fnDestroy();<br/>
var tr = $("#td" + id).parent().remove();<br/>
$('#dt table').dataTable();