gpt4 book ai didi

javascript - 将 JqGrid 列模式显示为日期和超链接显示 NAN/NAN/NAN

转载 作者:行者123 更新时间:2023-12-03 06:22:02 26 4
gpt4 key购买 nike

我有动态 JQGrid,其中一列是日期列。我从包含 URL 和日期的 feed 中获取数据。

我需要为“日期列”开发列模型,使其显示日期和超链接。但不幸的是,数据显示为 NAN/NAN/NAN (这可能是因为它将整个字符串 - <a>...</a> 视为日期而不是“20/8/2016”)。谁能告诉我如何以正确的文本而不是 NAN 显示日期?

注意:我什至应该确保维护日期的排序

工作的示例代码片段 - 当没有 anchor 标记时和不工作 - 当有 anchor 标记时。但是,无论 anchor 标记如何,当列模式为文本类型时,这始终有效 - 换句话说,这只发生在日期列,而不发生在其他列。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="http://trirand.com/blog/jqgrid/themes/ui.jqgrid.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://trirand.com/blog/jqgrid/js/jquery.jqGrid.min.js"></script>
<script src="http://trirand.com/blog/jqgrid/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript">
$(document).ready(function () {

var data = [{ 'Date': "<a href=https://google.com target=_blank style=text-decoration:underline;>20/8/2016</a>" },
{ 'Date': "<a href=https://google.com target=_blank style=text-decoration:underline;>21/8/2016</a>" },
{ 'Date': "<a href=https://google.com target=_blank style=text-decoration:underline;>22/8/2016</a>" },
{ 'Date': "2016-08-09T06:11:14.907Z" }, { 'Date': "2016-08-10T06:11:14.907Z" }
]
$("#grid").jqGrid({
datatype: 'jsonstring',
datastr: data,
colNames: ["Date"],
colModel: [{ name: 'Date', sorttype: 'date', formatter: 'date', formatoptions: {newformat:'n/j/Y'} }]
});
});
</script>
</head>
<body>
<table id="grid"></table>
</body>
</html>

最佳答案

jqgrid afterinsertrow使用

var data = [{ 'Date': "20/8/2016" },
{ 'Date': "20/8/2016" },
{ 'Date': "20/8/2016" },
{ 'Date': "2016-08-09T06:11:14.907Z" },
{ 'Date': "2016-08-10T06:11:14.907Z" }
]
$("#grid").jqGrid({
datatype: 'jsonstring',
datastr: data,
colNames: ["Date"],
colModel: [{ name: 'Date', sorttype: 'date', formatter: 'date', formatoptions: {newformat:'n/j/Y'} }],
**afterInsertRow : function(rowid, aData){
if(rowid == 1){
$("#grid").jqGrid('setCell' ,rowid, 'Date', "<a href=https://google.com target=_blank style=text-decoration:underline;>"+aData.Date+"</a>", {});
}
}**
});

关于javascript - 将 JqGrid 列模式显示为日期和超链接显示 NAN/NAN/NAN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38822640/

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