gpt4 book ai didi

ajax - 通过按钮加载 DataTable 数据 单击

转载 作者:行者123 更新时间:2023-12-04 14:12:25 29 4
gpt4 key购买 nike

我想通过单击按钮来填充 DataTable。最初 dataTable 应该是空的:

var searchText = $("#textBox").val();

Table = $("#customerTable").dataTable({
data:[],
"columns": [
{"data": "Id" },
{ "data": "Name" },
{ "data": "City" },
{ "data": "Country" }
]
//"serverSide": true
});

然后按钮单击:
$("#SearchButton").on("click", function (event) {

$.ajax({
url: "/LoadCustomers",
type: "post"
});
Table.rows.add(result).draw();
});

最佳答案

解决了 !!!

我的 table 看起来像这样:

Table = $("#customerTable").DataTable({
data:[],
columns: [
{ "data": "CompanyId" },
{ "data": "CompanyName" },
{ "data": "City" },
{ "data": "Country" }
],
rowCallback: function (row, data) {},
filter: false,
info: false,
ordering: false,
processing: true,
retrieve: true
});

按钮点击处理程序:
$("#customerSearchButton").on("click", function (event) {
$.ajax({
url: "",
type: "post",
data: { searchText: searchText }
}).done(function (result) {
Table.clear().draw();
Table.rows.add(result).draw();
}).fail(function (jqXHR, textStatus, errorThrown) {
// needs to implement if it fails
});
}

关于ajax - 通过按钮加载 DataTable 数据 单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26717168/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com