gpt4 book ai didi

javascript - 将查询结果设置为数据表的源

转载 作者:行者123 更新时间:2023-11-28 03:28:46 26 4
gpt4 key购买 nike

我正在尝试将数据表的源设置为从存储过程返回的数据。这是我的代码,但我的数据表未填充。有人可以帮助我更新此代码,以便用存储过程结果填充数据表吗?

This is my JavaScript

$("#btnClick").click(function () {
$('#example').DataTable({
ajax: {
url: getURL,
method: "GET"
},
columns: [
{ data: "Location" },
{ data: "TC" }
]
});
});

This is my HTML

<div id="table1">
<table id="example" class="display">
</table>
</div>
<br />
<div class="text-center">
<div class="btn-group">
<button type="button" id="btnClick">Button One</button>
</div>
</div>
@section Scripts {
<script>
var getURL = '@Url.Action("GTC")';
</script>
}

This is my Controller Code:

[ApiController]
[Route("api/EmpCheck")]
public class EmpCheckController : Controller
{
EmpCheck _context;

public EmpCheckController( context)
{
_context = context;
}

public IActionResult Index()
{
var VerifyAllEmpsOnDuty = _context.EmpCheckModel.FromSql("_GetClockedInEmps").ToList();
return View(VerifyAllEmpsOnDuty);
}
}

最佳答案

您可以直接将ajax源绑定(bind)到数据表。如果您的 API 工作正常。

you can do it by two way.

1- directly bind ajax source.

2- fetch record using ajax and then bind response to DataTable.

这是 both 的工作示例

关于javascript - 将查询结果设置为数据表的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58368800/

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