Exemple #1
0
        /// <summary>
        /// build headers expressions
        /// </summary>
        /// <param name="columns"></param>
        private void BuildColumnExpressions(IList <PivotColumn <T> > columns)
        {
            var             EntityType = typeof(T);
            var             listParameterExpression = Expression.Parameter(EntityType, "obj");
            PivotColumn <T> previousColumn          = null;

            foreach (var column in columns)
            {
                if (previousColumn != null)
                {
                    previousColumn.LowerColumn = column;
                    column.HigherColumn        = previousColumn;
                }
                previousColumn = column;
                if (column.ValueGetter == null)
                {
                    var propertyExpression = Expression.Property(listParameterExpression, column.PropertyName);
                    column.ValueGetter = Expression.Lambda <Func <T, dynamic> >(
                        Expression.Convert(propertyExpression, typeof(object)),
                        listParameterExpression).Compile();
                }
                if (column.TitleGetter == null)
                {
                    column.TitleGetter = (obj) => Convert.ToString(column.ValueGetter(obj));
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Build Header Cell recursively
        /// </summary>
        /// <param name="source"></param>
        /// <param name="column"></param>
        /// <param name="parent"></param>
        private void BuildHeaderCells(IEnumerable <T> source, PivotColumn <T> column, PivotHeaderCell <T> parent = null)
        {
            var list = column.Order == PivotOrder.Ascending
                            ? source.GroupBy(column.KeySelector).OrderBy(grp => grp.Key)
                            : source.GroupBy(column.KeySelector).OrderByDescending(grp => grp.Key);

            foreach (var group in list)
            {
                var cell = new PivotHeaderCell <T>(group.First(), column);
                column.Cells.Add(cell);
                if (parent != null)
                {
                    parent.__Children.Add(cell);
                }
                cell.Parent = parent;
                if (column.LowerColumn != null)
                {
                    BuildHeaderCells(group, column.LowerColumn, cell);
                }
            }
        }
Exemple #3
0
 internal PivotHeaderCell(T leadObjet, PivotColumn <T> column)
 {
     LeadObject = leadObjet;
     Column     = column;
 }