Пример #1
0
 void IList <GridColumn <T> > .Insert(int index, GridColumn <T> item)
 {
     _columns.Insert(index, item);
 }
Пример #2
0
        /// <summary>
        ///  Specifies a column should be constructed for the specified property.
        ///  add by zhangh 2013/06/03
        /// </summary>
        /// <param name="propertySpecifier"></param>
        /// <param name="fieldName"></param>
        /// <returns></returns>
        public IGridColumn <T> For(Expression <Func <T, object> > propertySpecifier, string fieldName)
        {
            var memberExpression = GetMemberExpression(propertySpecifier);
            var propertyType     = GetTypeFromMemberExpression(memberExpression);
            var declaringType    = memberExpression == null?string.IsNullOrEmpty(fieldName) ? null : typeof(T) : memberExpression.Expression.Type;

            var inferredName = memberExpression == null ? fieldName : memberExpression.Member.Name;
            var column       = new GridColumn <T>(propertySpecifier.Compile(), inferredName, propertyType);

            if (!string.IsNullOrEmpty(fieldName))
            {
                column.FieldName = fieldName;
            }
            else
            {
                string tmpName = ExpressionHelper.GetExpressionText(propertySpecifier);
                if (string.IsNullOrEmpty(tmpName) && memberExpression != null)
                {
                    tmpName = memberExpression.ToString().Substring(memberExpression.ToString().IndexOf(".") + 1);
                }

                column.FieldName = tmpName;
            }

            if (!string.IsNullOrEmpty(column.FieldName))
            {
                string[]      props       = column.FieldName.Split('.');
                Type          type        = typeof(T);
                PropertyInfo  property    = null;
                string        displayName = string.Empty;
                ModelMetadata metadata;
                foreach (string prop in props)
                {
                    property = type.GetProperty(prop);
                    if (property == null)
                    {
                        continue;
                    }

                    metadata = _metadataProvider.GetMetadataForProperty(null, type, property.Name);
                    if (!string.IsNullOrEmpty(metadata.DisplayName))
                    {
                        displayName += metadata.DisplayName;
                        column.Named(displayName);
                    }
                    type = property.PropertyType;
                }

                #region TODO: 格式化等其他信息 zhangh 2013/06/03
                //if (declaringType != null)
                //{
                //    metadata = _metadataProvider.GetMetadataForProperty(null, declaringType, inferredName);

                //    //if (!string.IsNullOrEmpty(metadata.DisplayName))
                //    //{
                //    //    displayName += metadata.DisplayName;
                //    //    column.Named(displayName);
                //    //}

                //    if (!string.IsNullOrEmpty(metadata.DisplayFormatString))
                //    {
                //        column.Format(metadata.DisplayFormatString);
                //    }
                //}
                #endregion
            }

            Add(column);

            return(column);
        }
Пример #3
0
 bool ICollection <GridColumn <T> > .Remove(GridColumn <T> column)
 {
     return(_columns.Remove(column));
 }
Пример #4
0
 int IList <GridColumn <T> > .IndexOf(GridColumn <T> item)
 {
     return(_columns.IndexOf(item));
 }
Пример #5
0
 bool ICollection <GridColumn <T> > .Contains(GridColumn <T> column)
 {
     return(_columns.Contains(column));
 }
Пример #6
0
 void ICollection <GridColumn <T> > .Add(GridColumn <T> column)
 {
     Add(column);
 }
Пример #7
0
 protected virtual void Add(GridColumn <T> column)
 {
     _columns.Add(column);
 }
        protected override void RenderHeaderCellStart(GridColumn <T> column)
        {
            var attributes = new Dictionary <string, object>(column.HeaderAttributes);

            if (IsSortingEnabled && column.IsSortable)
            {
                //bool isSortedByThisColumn = (GridModel.SortOptions.Column == GenerateSortColumnName(column));
                bool isSortedByThisColumn = (GridModel.SortOptions.Column == column.FieldName);

                if (isSortedByThisColumn)
                {
                    string sortClass = GridModel.SortOptions.Direction == SortDirection.Ascending ? "grid-sort-asc" : "grid-sort-desc";

                    if (attributes.ContainsKey("class") && attributes["class"] != null)
                    {
                        sortClass = string.Join(" ", new[] { attributes["class"].ToString(), sortClass });
                    }

                    attributes["class"] = sortClass;
                }
            }

            //add by zhangh 2013/05/31 排序列设置
            if (column.IsSortable)
            {
                attributes["sortable"] = "true";
            }

            if (column.IsQueryable)
            {
                attributes["queryable"] = "true";
            }

            if (column.IsEditable)
            {
                attributes["editable"] = "true";
            }

            if (column.Selectable)
            {
                attributes["selectable"] = "true";
            }

            if (column.Reliable)
            {
                attributes["reliable"] = "true";
            }

            if (column.IsSumColumn)
            {
                attributes["issum"] = "true";
            }

            if (!string.IsNullOrEmpty(column.ColumnEqualTo))
            {
                attributes["equalto"] = column.ColumnEqualTo;
            }

            attributes["field"] = column.FieldName;

            if (!column.IsHide)
            {
                attributes["width"] = column.ColWidth;
            }


            string attrs = BuildHtmlAttributes(attributes);

            if (attrs.Length > 0)
            {
                attrs = " " + attrs;
            }

            RenderText(string.Format("<th{0}><div>", attrs));
        }
 protected virtual string GenerateSortColumnName(GridColumn <T> column)
 {
     //Use the explicit sort column name if specified. If not possible, fall back to the property name.
     //If the property name cannot be inferred (ie the expression is not a MemberExpression) then try the display name instead.
     return(column.SortColumnName ?? column.Name ?? column.DisplayName);
 }