【问题标题】:Use column formatting to customize SharePoint使用列格式自定义 SharePoint
【发布时间】:2020-01-31 12:10:58
【问题描述】:

我正在关注这篇文章: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/column-formatting#formatting-items-based-on-arbitrary-dates-advanced

我有一个带有续订日期的 SP 列表,如果日期小于今天 - 31 天,我希望将其标记,因此我将文章中的示例修改为:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if([$Renewal_x0020_Date] <= @now - 2678400000‬, '#ff0000', '')"
  }
}

因此,根据“要在日期中添加一天,您将添加 (24*60*60*1000 = 86,400,000)”,我将其乘以 31。

不幸的是,JSON 没有格式化我的视图。

有人可以指导我吗?

谢谢

斯拉维克

【问题讨论】:

  • 转到列表设置(齿轮>列表设置),单击 RenewalDate 列并在 url (...&Field=RenewalDate) 中查看列的内部名称。尝试使用 $RenewalDate

标签: sharepoint formatting


【解决方案1】:

列格式似乎只适用于现代体验。以下是结果。

新/现代体验

经典体验:

如果您的列表当前设置为以经典视图打开,请尝试切换体验。

【讨论】:

【解决方案2】:

$RenewalDate 的第一个示例 试试这个三元 (?) 运算符代码

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "@currentField",
   "style": {
      "color": {
         "operator": "?",
         "operands": [
            {
               "operator": "<=",
               "operands": [
                  "[$RenewalDate]",
                  {
                     "operator": "+",
                     "operands": [
                        "@now",
                        -2678400000
                     ]
                  }
               ]
            },
            "#ff0000",
            ""
         ]
      }
   }
}

第二个例子是名称中带有空格的列$Renewal_x0020_Date

{
   "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
   "elmType": "div",
   "txtContent": "@currentField",
   "style": {
      "color": {
         "operator": "?",
         "operands": [
            {
               "operator": "<=",
               "operands": [
                  "[$Renewal_x0020_Date]",
                  {
                     "operator": "+",
                     "operands": [
                        "@now",
                        -2678400000
                     ]
                  }
               ]
            },
            "#ff0000",
            ""
         ]
      }
   }
}

编辑: 使用 Excel 样式的表达式语法

没有空格的列$RenewalDate

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if([$RenewalDate] <= @now - 2678400000, '#ff0000', '')"
  }
}

带空格的列$Renewal_x0020_Date

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "style": {
    "color": "=if([$Renewal_x0020_Date] <= @now - 2678400000, '#ff0000', '')"
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多