微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Kendo Grid React 中指定日期格式

如何解决在 Kendo Grid React 中指定日期格式

我有一个 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 格式-2014-08-14T15:30:10Z

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

解决方法

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

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

,

您可以将 '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>
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。