【问题标题】:Specify date format in Kendo Grid React在 Kendo Grid React 中指定日期格式
【发布时间】:2021-01-15 15:21:11
【问题描述】:

我有一个 Kendo React Grid 来显示我从 Sharepoint 列表中获取的数据。这是一个简单的网格,如此链接所示 - https://www.telerik.com/kendo-react-ui/components/grid/get-started/

<Column field="StartDate" title="Start Date" width="200px" format="{0:MMM yyyy}" />
<Column field="EndDate" title="End Date" width="200px" format="{0:MMM yyyy}" />

现在日期是 ISO 格式,例如 this-2014-08-14T15:30:10Z

如何转换为 mm/dd/yyyy 格式?上述格式属性的值似乎不起作用。

【问题讨论】:

  • 能否提供一个可运行的代码示例?如果不能提供可运行的示例,那么至少根据 StackOverflow 指南提供完整代码。
  • 你也错过了你使用的剑道网格的味道。其中有很多用于 jquery、angular、asp.net 等的 kendo。
  • 我无法共享可运行代码。这是一个简单的剑道反应网格。我已经在问题标题中提到了剑道网格的味道:) 另外,我编辑了我的问题。任何帮助都会很棒:)

标签: kendo-grid kendo-react-ui


【解决方案1】:

KendoReact Grid 只格式化有效的 JavaScript 日期对象。

telerik 有澄清: https://www.telerik.com/kendo-react-ui/knowledge-base/grid-date-format/

【讨论】:

    【解决方案2】:

    您可以将 'cell' 属性中的自定义函数传递给 Column。使用“时刻”根据您的格式自定义日期。

        <Column field="StartDate" title="Start Date" width="200px" cell={this.myCustomDateCell}" />
    
    
    
    myCustomDateCell = props => {
        if (props.dataItem[props.field] !== '') {
          return <td>{moment(props.dataItem[props.field]).format("MM/DD/YYYY")}</td>
        }
        return <td>{props.dataItem[props.field]}</td>
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      • 2014-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      相关资源
      最近更新 更多