예제 #1
0
        private static async Task <string> FormatValue(ITableColumn col, object?value)
        {
            var ret = "";

            if (col.Formatter != null)
            {
                // 格式化回调委托
                ret = await col.Formatter(value);
            }
            else if (!string.IsNullOrEmpty(col.FormatString))
            {
                // 格式化字符串
                ret = Utility.Format(value, col.FormatString);
            }
            else if (col.PropertyType.IsEnum())
            {
                ret = col.PropertyType.ToDescriptionString(value?.ToString());
            }
            else if (col.PropertyType.IsDateTime())
            {
                ret = Utility.Format(value, CultureInfo.CurrentUICulture.DateTimeFormat);
            }
            else if (value is IEnumerable <object> v)
            {
                ret = string.Join(",", v);
            }
            else
            {
                ret = value?.ToString() ?? "";
            }
            return(ret);
        }
예제 #2
0
 /// <summary>
 /// 获得 指定单元格数据方法
 /// </summary>
 /// <param name="col"></param>
 /// <param name="item"></param>
 /// <returns></returns>
 protected RenderFragment GetValue(ITableColumn col, TItem item) => async builder =>
 {
     if (col.Template != null)
     {
         builder.AddContent(0, col.Template.Invoke(item));
     }
     else
     {
         string content = "";
         var    val     = GetItemValue(col.GetFieldName(), item);
         if (col.Formatter != null)
         {
             // 格式化回调委托
             content = await col.Formatter(val);
         }
         else if (!string.IsNullOrEmpty(col.FormatString))
         {
             // 格式化字符串
             content = val?.Format(col.FormatString) ?? "";
         }
         else if (col.FieldType.IsEnum())
         {
             content = col.FieldType.ToDescriptionString(val?.ToString());
         }
         else
         {
             content = val?.ToString() ?? "";
         }
         builder.AddContent(0, content);
     }
 };