using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; namespace WalkingTec.Mvvm.Core { /// /// GridColumn Extension /// public static class GridHeaderExtension { /// /// 创建表头 /// /// /// /// /// 绑定猎头表达式 /// 宽度 /// public static GridColumn MakeGridHeader(this IBasePagedListVM self , Expression> columnExp , int? width = null ) where T : TopBasePoco where V : ISearcher { MemberExpression me = null; if (columnExp is MemberExpression) { me = columnExp as MemberExpression; } else if (columnExp is LambdaExpression) { var le = columnExp as LambdaExpression; if (le.Body is MemberExpression) { me = le.Body as MemberExpression; } } var alignType = GridColumnAlignEnum.Center; if (me != null) { var propType = me.Type; if (propType == typeof(string)) { alignType = GridColumnAlignEnum.Left; } } return new GridColumn(columnExp, width) { ColumnType = GridColumnTypeEnum.Normal, Align = alignType }; } /// /// 创建一个间隙列 /// /// /// /// /// public static GridColumn MakeGridHeaderSpace(this IBasePagedListVM self) where T : TopBasePoco where V : ISearcher { return new GridColumn() { ColumnType = GridColumnTypeEnum.Space }; } /// /// 创建一个父级表头 /// /// /// /// /// 标题 /// public static GridColumn MakeGridHeaderParent(this IBasePagedListVM self, string title ) where T : TopBasePoco where V : ISearcher { return new GridColumn() { Title = title }; } public static GridColumn MakeGridHeaderAction(this IBasePagedListVM self , string title = null , int? width = 160 , int? rowspan = null ) where T : TopBasePoco where V : ISearcher { return new GridColumn() { ColumnType = GridColumnTypeEnum.Action, Width = width, Fixed = GridColumnFixedEnum.Right, Title = title ?? CoreProgram._localizer?["Sys.Operation"] }; } #region GridColumn Property Setter /// /// 设定字段名 /// /// /// /// 字段名的设定非常重要,是表格数据列的唯一标识,默认属性对应的名字 /// public static GridColumn SetField(this GridColumn self, string field) where T : TopBasePoco { self.Field = field; return self; } /// /// 设定标题名称 /// /// /// /// 即表头各列的标题,默认属性对应的 DisplayName 或 属性名 /// public static GridColumn SetTitle(this GridColumn self, string title) where T : TopBasePoco { self.Title = title; return self; } /// /// 设定列宽 /// /// /// /// 列宽的设定也通常是必须的(“特殊列”除外,如:复选框列、工具列等),它关系到表格的整体美观程度。 /// public static GridColumn SetWidth(this GridColumn self, int width) where T : TopBasePoco { self.Width = width; return self; } /// /// 单元格事件名称 /// /// /// /// /// public static GridColumn SetEvent(this GridColumn self, string eEvent) where T : TopBasePoco { self.Event = eEvent; return self; } ///// ///// 设定当前列头 列横跨的单元格数 ///// ///// ///// ///// 这种情况下不用设置 Field 和 Width ///// //public static GridColumn SetColspan(this GridColumn self, int colspan) // where T : TopBasePoco //{ // self.Colspan = colspan; // return self; //} ///// ///// 设定当前列头 纵向跨越的单元格数 ///// ///// ///// ///// 纵向跨越的单元格数 ///// //public static GridColumn SetRowspan(this GridColumn self, int rowspan) // where T : TopBasePoco //{ // self.Rowspan = rowspan; // return self; //} /// /// 设定是否允许排序 (ASCII码排序) /// /// /// /// 如果设置 true,则在对应的表头显示排序icon,从而对列开启排序功能。 /// public static GridColumn SetSort(this GridColumn self, bool sort = true) where T : TopBasePoco { self.Sort = sort; return self; } /// /// 设定是否固定列 /// /// /// /// 如果设置 Left 或 Right,则对应的列将会被固定在左或右,不随滚动条而滚动。 /// public static GridColumn SetFixed(this GridColumn self, GridColumnFixedEnum? @fixed) where T : TopBasePoco { self.Fixed = @fixed; return self; } /// /// 设定对齐方式 /// /// /// /// /// public static GridColumn SetAlign(this GridColumn self, GridColumnAlignEnum align) where T : TopBasePoco { self.Align = align; return self; } ///// ///// 设定是否允许编辑 ///// ///// ///// ///// 如果设置 true,则对应列的单元格将会被允许编辑,目前只支持type="text"的input编辑。 ///// //public static GridColumn SetEdit(this GridColumn self, bool edit = true) // where T : TopBasePoco //{ // self.Edit = edit; // return self; //} ///// ///// 设定自定义模板 ///// ///// ///// ///// 在默认情况下,单元格的内容是完全按照数据接口返回的content原样输出的, ///// 如果你想对某列的单元格添加链接等其它元素,你可以借助该参数来轻松实现。 ///// 这是一个非常实用的功能,你的表格内容会因此而丰富多样。 ///// ///// //public static GridColumn SetTemplet(this GridColumn self, string templet) // where T : TopBasePoco //{ // self.Templet = templet; // return self; //} [Obsolete("该方法已经被弃用,请使用 SetHide 代替")] public static GridColumn SetHidden(this GridColumn self, bool hidden = true) where T : TopBasePoco { return self; } /// /// 是否隐藏 /// /// /// /// /// public static GridColumn SetHide(this GridColumn self, bool hide = true) where T : TopBasePoco { self.Hide = hide; return self; } /// /// 设定列宽不可改变 /// /// /// /// /// public static GridColumn SetUnResize(this GridColumn self, bool unresize = true) where T : TopBasePoco { self.UnResize = unresize; return self; } /// /// 设定单元格编辑类型 /// /// /// /// 单元格编辑类型 /// listitems /// public static GridColumn SetEditType(this GridColumn self, EditTypeEnum editType = EditTypeEnum.Text, List listitems = null) where T : TopBasePoco { self.EditType = editType; self.ListItems = listitems; return self; } #endregion } }