You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让MudDataGrid的PropertyColumn用DateTime过滤排序却显示字符串属性?

解决方案

要实现基于PickupDate过滤排序,但显示PickupScheduledEndDateTime内容的需求,只需在原PropertyColumn中添加CellTemplate来自定义单元格显示内容即可,核心逻辑是保留Property属性指定的PickupDate用于数据操作,同时用模板替换显示值:

<PropertyColumn Property="x => x.PickupDate" Title="Shipping Date" IsEditable="false">
    <CellTemplate>
        @context.Item.PickupScheduledEndDateTime
        <!-- 可选:处理空值情况 -->
        <!-- @(context.Item.PickupScheduledEndDateTime ?? "无数据") -->
    </CellTemplate>
</PropertyColumn>

关键说明:

  • Property="x => x.PickupDate":保持这个配置,确保过滤、排序功能基于PickupDate(DateTime类型)正常工作
  • <CellTemplate>:通过模板覆盖单元格默认显示内容,直接绑定PickupScheduledEndDateTime字符串值
  • 如果PickupScheduledEndDateTime可能为空,可添加空值判断避免显示空白

内容的提问来源于stack exchange,提问作者MikeSteigerwald

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 03:14:51