如何在Acumatica表格的字段及选择器字段中显示ID-Description格式
如何在Acumatica的Grid及Selector字段中显示ID-Description格式
Grid字段显示ID-Description格式
针对Grid中的普通字段(非Selector),有两种常用实现方式:
方式1:通过DAC计算字段拼接
- 在对应DAC中新增字符串类型字段,用于存储拼接后的ID-Description内容:
[PXDBString(100, IsUnicode = true)] [PXUIField(DisplayName = "目标字段名")] public virtual string TargetIDDesc { get; set; }
- 在页面的RowSelected事件中,获取ID对应的描述并拼接赋值:
protected void DACName_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { var row = e.Row as DACName; if (row == null) return; // 示例:获取InventoryItem的描述 var item = PXSelectorAttribute.Select<DACName.inventoryID>(cache, row) as InventoryItem; if (item != null) { row.TargetIDDesc = $"{row.InventoryID} - {item.Descr}"; } }
- 在Grid布局中添加这个
TargetIDDesc字段即可。
方式2:利用Acumatica自带字段的描述显示
如果字段是Acumatica自带的关联字段(如InventoryID、CustomerID),直接在Grid列的属性设置中,将Display Mode改为Description,系统会自动显示ID - 描述的组合格式。
表格内Selector字段显示ID-Description格式
针对Grid内的Selector字段,通过DAC的属性配置即可实现:
- 在DAC的字段定义中,使用
[PXSelector]属性并指定DescriptionField和SubstituteKey参数,让Selector同时显示ID与描述:
[PXDBInt] [PXSelector( typeof(Search<InventoryItem.inventoryID>), typeof(InventoryItem.inventoryCD), // 显示的ID字段 typeof(InventoryItem.descr), // 描述字段 DescriptionField = typeof(InventoryItem.descr), SubstituteKey = typeof(InventoryItem.inventoryCD) )] [PXUIField(DisplayName = "库存项目")] public virtual int? InventoryID { get; set; }
- 确保Grid中该Selector字段的Display Mode设置为
Text(默认值),而非Value,否则只会显示纯ID。
若需更自定义的显示格式,可修改Selector的RowTemplate,手动拼接ID和描述的HTML结构,但上述方式是最简便的标准实现。
内容的提问来源于stack exchange,提问作者Giri
相关产品推荐
相关产品推荐

