列表动态创建列,如何设置列的属性原创
金蝶云社区-watson
watson
0人赞赏了该文章 477次浏览 未经作者许可,禁止转载编辑于2023年03月01日 09:20:44

列表动态创建列,可以参与二开案例示例

https://vip.kingdee.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;

        }


图标赞 0
0人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!