列表动态创建列,如何设置列的属性
列表动态创建列,可以参与二开案例示例
https://wenku.my7c.com/article/130367358388408320?productLineId=1&isKnowledge=2
业务需要可能对动态创建列要进行属性的设置,如金额小数点、汇总值,即字段在BOS上的属性都可以设置
可以二开案例代码
public static T CreateField<T, K>(Context ctx, string entityKey, string fieldName, string caption, PayItemAmountFieldSetDto amountFieldSetDto = null,
int columnWidth = 100,
string propName = "", ElementType elementType = null)
where T : FieldAppearance, new()
where K : Field, new()
{
if (amountFieldSetDto == null)
{
amountFieldSetDto= new PayItemAmountFieldSetDto();
amountFieldSetDto.DisplayByReallyPrecision = false;
amountFieldSetDto.FieldPrecision = 18;
amountFieldSetDto.FieldScale = 2;
amountFieldSetDto.ZeroShow = 1;
}
var fieldAppearance = new T();
fieldAppearance.Field = new K();
if (elementType != null)
{
PropertyUtil.SetAppearenceDefaultValue(fieldAppearance, elementType, ctx.UserLocale.LCID);
PropertyUtil.SetBusinessDefaultValue(fieldAppearance.Field, elementType, ctx.UserLocale.LCID);
}
fieldAppearance.Key = fieldName;
fieldAppearance.EntityKey = entityKey;
fieldAppearance.Caption = new LocaleValue(caption, ctx.UserLocale.LCID);
fieldAppearance.Width = new LocaleValue(columnWidth.ToString(), ctx.UserLocale.LCID);
fieldAppearance.Locked = -1;
fieldAppearance.Visible = -1;
//
fieldAppearance.Field.Key = fieldName;
fieldAppearance.Field.EntityKey = entityKey;
fieldAppearance.Field.Name = fieldAppearance.Caption;
fieldAppearance.Field.FieldName = fieldName;
fieldAppearance.Field.PropertyName = string.IsNullOrWhiteSpace(propName) ? fieldName : propName;
fieldAppearance.Field.FireUpdateEvent = 0;
//设置 字段属性
if (fieldAppearance.Field is AmountField)
{
var amountField = (AmountField)fieldAppearance.Field;
amountField.ZeroShow = amountFieldSetDto.ZeroShow;
amountField.DisplayByReallyPrecision = amountFieldSetDto.DisplayByReallyPrecision;
amountField.FieldScale = amountFieldSetDto.FieldScale;
amountField.FieldPrecision = amountFieldSetDto.FieldPrecision;
amountField.SummaryType = SummaryType.SUM_VALUE;
}
return fieldAppearance;
}
老师,动态创建的列在列表导出时,值为空,有啥办法么
列表动态创建列,如何设置列的属性
本文2024-09-16 18:32:16发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-22791.html