使用DataTable时如何显示DateTime?
我正在使用Razor页面在ASP.NET Core中构建Web应用程序。但是,我还想尝试使用一些JavaScript显示数据表。我想显示属性的启动时间,末日和添加的属性,这些属性是类型的DateTime。但是如果没有进行很多背景转换,我就无法使它起作用。
我的问题是,显示存储在DateTime属性中的值的最简单方法是什么?
这就是我的JS文件的样子,它从自定义类移动的对象中显示信息:
$(document).ready(function () {
$('#DT_load').DataTable({
"ajax": {
"url": "/api/Shift",
"type": "GET",
"datatype":"json"
},
"columns": [
{ "data": "user.name", "width": "25%" },
{ "data": "location.name", "width": "25%" },
{**<!-- Here i want to display DateTime properties values -->**
"data": "id",
"render": function (data) {
return `<div class="w-75 btn-group" >
<a href="/Admin/Shifts/upsert?id=${data}" class="btn btn-success text-white mx-2">
<i class="bi bi-pencil-square"></i> </a>
<a href="/Admin/Shifts/upsert?id=${data}" class="btn btn-danger text-white mx-2">
<i class="bi bi-trash-fill"></i> </a>
</div>`
},
"width":"15%"
},
],
"width":"100%"
});
});
我正在使用一个控制器,该控制器获取具有特定属性的所有属性,但包括属性也不起作用。
I am building a web app in ASP.NET Core using Razor Pages. However, i also wanted to try using some javascript to display a datatable. I want to display the properties StartTime, EndTime, and Added, which are of the type DateTime. But i cannot get it to work without doing a lot of background conversions.
My question is, what would be the simplest way to display the values stored in the DateTime properties?
This is what my js-file looks like, it displays information from an object of the custom class Shift:
$(document).ready(function () {
$('#DT_load').DataTable({
"ajax": {
"url": "/api/Shift",
"type": "GET",
"datatype":"json"
},
"columns": [
{ "data": "user.name", "width": "25%" },
{ "data": "location.name", "width": "25%" },
{**<!-- Here i want to display DateTime properties values -->**
"data": "id",
"render": function (data) {
return `<div class="w-75 btn-group" >
<a href="/Admin/Shifts/upsert?id=${data}" class="btn btn-success text-white mx-2">
<i class="bi bi-pencil-square"></i> </a>
<a href="/Admin/Shifts/upsert?id=${data}" class="btn btn-danger text-white mx-2">
<i class="bi bi-trash-fill"></i> </a>
</div>`
},
"width":"15%"
},
],
"width":"100%"
});
});
I am using a controller that gets all properties with specific properties, but including the properties doesn't work either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要在DataTable中显示Datatime类型数据,则只需要直接显示。例如:
模型:
操作:
JS:
If you want to show datatime type data in datatable,you only need to show it directly.For example:
model:
action:
js: