c# - 带有数据表的索引页面在显示搜索框之前大约需要 6-7 秒
问题描述
我有一个简单的索引页面。当我加载只有 500 条记录的页面时,搜索框会立即显示。但是对于 12k 条记录,这需要一些时间。有没有办法可以显示 LOADING 消息,并且在加载搜索框后,LOADING 消息会消失。
这是 Index.cshtml
@model IEnumerable<BSMV2.Models.StoAppnOrgView>
<h2>LIST OF STONES</h2>
<table id="applicationTable" class="table table-striped table-bordered">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Stone)
</th>
<th>
@Html.DisplayNameFor(model => model.Applicant)
</th>
<th>
@Html.DisplayNameFor(model => model.Org)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Stone)
</td>
<td>
@Html.DisplayFor(modelItem => item.Applicant)
</td>
<td>
{@Html.DisplayFor(modelItem => item.Org)
</td>
<td>
@Html.ActionLink("Details", "Details", new { Id = item.Id })
</td>
</tr>
}
</tbody>
@section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$('#applicationTable').DataTable();
});
</script>}
这是控制器
public async Task<ActionResult> Index()
{
return View(await db.StoAppnOrgViewObj.ToListAsync());
}
解决方案
您不应该在 UI 上加载所有 12k 数据。取而代之的是使用服务器端分页,这将为用户提供类似的体验,但性能方面会更快。系统不会变慢。数据会随着时间的推移而增长,将来无论如何您都必须转向服务器端逻辑。
您还可以使用数据表附带的进度指示器。您只需执行以下操作:
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "../server_side/scripts/test.php"
} );
对于服务器端逻辑,您可以按照此处的代码进行操作。
推荐阅读
- sql - 在执行脚本中使用参数作为日期
- python - 如何在使用 Azure 认知语音翻译 API 时使用 python sdk 识别说话者?
- python - 错误属性错误:“列表”对象没有属性“发送键”
- sql - Azure DB 上的简单 SQL 更新性能不佳
- arrays - `.=` 什么时候比 `=` 更有效?
- http - 使用 wrk 对 nginx 反向代理进行负载测试时如何找出大量非 2xx 或 3xx 响应背后的错误
- firebase - 是否有任何关于开发用户聊天消息屏幕的教程/链接,类似于 AirBnB 或 Instagram 等应用程序?
- python - 从 xml 到封面要求列表
- javascript - Node.js - Discord.js - 尝试在嵌套地图中导航。- UnhandledPromiseRejectionWarning
- product - 如何在产品编辑页面(管理员)Prestashop 中创建自定义字段