gpt4 book ai didi

javascript - 服务器端数据从 C# 加载到 jquery 数据表中

转载 作者:行者123 更新时间:2023-11-28 08:07:53 24 4
gpt4 key购买 nike

嗨,我已经成功实现了 jquery 数据表服务器端调用,但我无法在 html View 中加载数据它只是说处理这是我的 Js 代码

 $('#internetTable').dataTable({
'bProcessing': true,
'bServerSide': true,
'sAjaxSource': 'api/values/GetInternetSales'
"aoColumns": [
{ "mData": "Calls" },
{ "mData": "LevelOneOperators" },
{ "mData": "LevelTwoOperators" },
{ "mData": "Issueraised" },
{ "mData": "SalesDate" },
{ "mData": "AutomaticResponses" }

]
});

这是 html 代码

<table id="internetTable" class="table table-bordered table-hover">
<thead>
<tr>
<th >Date</th>
<th>Issue Raised</th>
<th>Level One Operators</th>
<th >Level Two Operators</th>
<th>Automatic Responses</th>
<th>Calls</th>
</tr>
</thead>
</table>

从服务器得到的响应是

{"sEcho":"2","iTotalRecords":10,"iDisplayStart":1,"iDisplayEnd":1,"iDisplayLength":10,"iTotalDisplayRecords":100,"InternetDataList":[{"Calls":"320","LevelOneOperators":"1","LevelTwoOperators":"7","Issueraised":"1","SalesDate":"2010-11-25T00:00:00","AutomaticResponses":235}]}

现在,我只想问一下,我需要对JS代码进行哪些修改才能在表中解析它,因为我已经搜索了很多,但无法得到任何解决方案。

最佳答案

得到答案,我需要在js中添加以下代码:

$('#internetTable').dataTable({
'bProcessing': true,
'bServerSide': true,
"sServerMethod": "GET",
// to enable Pagination
"sPaginationType": "full_numbers",
'sAjaxSource': 'api/values/GetInternetSales',
"sAjaxDataProp": "InternetDataList",
"aoColumnDefs": [{
"mData": "InternetDataList"
}],
"aoColumns": [
{ "mData": "Calls" },
{ "mData": "LevelOneOperators" },
{ "mData": "LevelTwoOperators" },
{ "mData": "Issueraised" },

{ "mData": "AutomaticResponses" },
{ "mData": "SalesDate" }


]
});

这里 sAjaxDataProp 是您的数据名称,在我的例子中它是 InternetDataList,默认它是 aadata

关于javascript - 服务器端数据从 C# 加载到 jquery 数据表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24624907/

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