我有一个具有日历视图的 Sharepoint 列表,其中日期基于标题为“ExpirationDate”的列。
我想配置日历视图,以便过期日期在今天和从今天起 7 天之间的项目具有红色背景颜色。不幸的是,条件格式选项只有一个相对日期,那就是今天。我尝试使用条件格式选项来获取基本代码并进行修改,但是当我用“@now + 604800000”替换 7 天后的静态日期时,它无法识别该日期。
此外,由于某种原因,我的 ExpirationDate 列被引用为 [$Expiration_x0020_Date]——我只能假设是因为标题中最初有一个空格。
SP生成的代码: {
“$schema”:https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json,
“附加事件类”:{
"operator": ":",
"operands": [
{
"operator": "&&",
"operands": [
{
"operator": ">=",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"[$Expiration_x0020_Date]"
]
}
]
}
]
},
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"@now"
]
}
]
}
]
}
]
},
{
"operator": "<=",
"operands": [
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"[$Expiration_x0020_Date]"
]
}
]
}
]
},
{
"operator": "Date()",
"operands": [
{
"operator": "toDateString()",
"operands": [
{
"operator": "Date()",
"operands": [
"Thu Sep 14 2023"
]
}
]
}
]
}
]
}
]
},
"=if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgDarkRed' , 'sp-css-backgroundColor-BgCoral sp-css-color-CoralFont')",
""
]
}
}
正如我所说,尝试用相对日期来细分指定日期,没有骰子。
尝试对您的 SharePoint 在线现代列表日历视图使用如下 JSON 格式代码:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
"additionalEventClass": "=if([$Expiration_x0020_Date] >= @now && [$Expiration_x0020_Date] <= addDays(@now, 7), if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgRed', 'sp-css-backgroundColor-BgDustRose sp-css-color-DustRoseFont')+' sp-field-fontSizeSmall', if(@isSelected == true, 'sp-css-color-WhiteFont sp-css-backgroundColor-BgGray' , 'sp-css-backgroundColor-BgLightGray sp-css-color-LightGrayFont')+' sp-field-fontSizeSmall')"
}
其中
Expiration_x0020_Date
是 SharePoint 列表列的内部名称。您可以按照本文获取 SharePoint 列表列的内部名称:如何在 SharePoint Online 中查找列的内部名称?
相关参考:SharePoint:使用 JSON 格式突出显示选定的列表项行 -
@isSelected