Esempio n. 1
0
        public virtual void RenderTableHeader()
        {
            Writer.Write("<thead>");
            Writer.Write("<tr>");
            var nextSortOrder = GridModel.Multisort ? (OrderedVisibleColumns.Any(x => x.Value.SortOrder.HasValue)
                                           ? (OrderedVisibleColumns.Where(x => x.Value.SortOrder.HasValue).Max(x => x.Value.SortOrder) + 1) : 0)
                                           : 0;

            if (IsGroupGrid || GridModel.HierarchyUrl != null)
            {
                Writer.Write("<th class=\"hierarchy-cell\"></th>");
            }

            foreach (var column in OrderedVisibleColumns)
            {
                RenderColumnHeader(column.Value, column.Key, nextSortOrder.GetValueOrDefault(0), false);
            }

            if (IsGroupGrid || GridModel.HierarchyUrl != null)
            {
                Writer.Write("<th class=\"hierarchy-cell-right\"></th>");
            }

            Writer.Write("</tr>");
            Writer.Write("</thead>");
        }
Esempio n. 2
0
        public virtual void RenderGroupingHeader()
        {
            if (OrderedVisibleColumns.All(x => x.Value.GroupKeyProperty == null))
            {
                return;
            }

            Writer.Write("<div class=\"grouping-header {0}\">", GroupingHeaderClass);

            if (IsGroupGrid)
            {
                foreach (var column in OrderedVisibleColumns.Where(c => c.Value.GroupOrder.HasValue).OrderBy(x => x.Value.GroupOrder))
                {
                    RenderGroupIndicator(column.Value, column.Key);
                }
            }
            else
            {
                Writer.Write("<p class=\"grouping-header-empty\">");
                Writer.Write(GridRenderOptions.EmptyGroupHeaderText);
                Writer.Write("</p>");
            }

            Writer.Write("</div>");
        }
        public override void RenderTableRow(TModel item, IEnumerable <KeyValuePair <string, IGridColumn <TModel> > > columns, bool alternate, int level = 0, bool empty = false)
        {
            var tr          = new TagBuilder("tr");
            var isHierarchy = GridModel.HierarchyUrl != null;

            var rowAttributes = GridModel.RowAttributes != null?GridModel.RowAttributes(item, HtmlHelper) : null;

            tr.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(rowAttributes));

            if (alternate)
            {
                tr.Attributes["class"] = tr.Attributes.ContainsKey("class")? String.Format("{0} {1}", tr.Attributes["class"], AlternateRowClass): AlternateRowClass;
            }

            Writer.Write(tr.ToString(TagRenderMode.StartTag));

            if (isHierarchy)
            {
                if (empty)
                {
                    Writer.Write("<td class=\"hierarchy-cell\"></td>");
                }
                else
                {
                    Writer.Write("<td class=\"hierarchy-cell\"><a href=\"{0}\" class=\"grid-icon {1} plus\"></a></td>", GridModel.HierarchyUrl(item, UrlHelper), GridHierarchyLinkClass);
                }
            }

            var cols = columns as KeyValuePair <string, IGridColumn <TModel> >[] ?? columns.ToArray();

            for (var i = 0; i < cols.Length; i++)
            {
                var td = new TagBuilder("td");
                td.MergeAttributes(cols[i].Value.Attributes);
                var value = item != null?GetCellValue(cols[i].Value, item) : null;

                Writer.Write(td.ToString(TagRenderMode.StartTag));
                if (i == 0)
                {
                    var padding = new StringBuilder();
                    for (var j = 0; j < level * GridModel.SeparatorLevelLength; j++)
                    {
                        padding.Append("&nbsp;");
                    }
                    Writer.Write(padding.ToString());
                }
                value = empty ? "&nbsp;" : value;
                Writer.Write(value);
                Writer.Write("</td>");
            }

            if (isHierarchy)
            {
                Writer.Write("<td class=\"hierarchy-cell-right\"></td>");
            }

            Writer.Write("</tr>");

            if (isHierarchy)
            {
                Writer.Write("<tr style=\"display:none;\"><td class=\"hierarchy-cell\"></td>");
                Writer.Write("<td class=\"grid-hierarchy-row\" colspan=\"{0}\"></td>", OrderedVisibleColumns.Count());
                Writer.Write("<td class=\"hierarchy-cell-right\"></td>");
                Writer.Write("</tr>");
            }
            var alt = alternate;

            if (GridModel.ChildSelector != null)
            {
                var childrens = GridModel.ChildSelector(item);
                if (childrens != null)
                {
                    level = level + 1;
                    foreach (var children in childrens)
                    {
                        alt = !alt;
                        RenderTableRow(children, cols, alt, level);
                    }
                }
            }
        }
        public override void RenderGroupTable(TModel[] items, IGridGroupOptions groupOptions, IPagedList paginationViewModel)
        {
            var isHierarchy = GridModel.HierarchyUrl != null;

            Writer.Write("<div class=\"grid-group-wrap\">");
            Writer.Write("<table class=\"grid-group-table\"><thead>");
            var nextSortOrder = GridModel.Multisort ? (OrderedVisibleColumns.Any(x => x.Value.SortOrder.HasValue)
                                           ? (OrderedVisibleColumns.Where(x => x.Value.SortOrder.HasValue).Max(x => x.Value.SortOrder) + 1) : 0)
                                           : 0;

            if (isHierarchy)
            {
                Writer.Write("<th class=\"hierarchy-cell\"></th>");
            }

            foreach (var column in OrderedVisibleColumns)
            {
                RenderColumnHeader(column.Value, column.Key, nextSortOrder.GetValueOrDefault(0), true);
            }

            if (isHierarchy)
            {
                Writer.Write("<th class=\"hierarchy-cell-right\"></th>");
            }

            Writer.Write("</thead>");
            Writer.Write("<tbody>");
            var alternate = false;

            for (var i = 0; i < items.Length; i++)
            {
                RenderTableRow(items[i], OrderedVisibleColumns, alternate);
                alternate = !alternate;
            }

            if (GridModel.ShowEmptyRowsInGroup)
            {
                for (var i = items.Length; i < GridModel.PageSizeInGroup; i++)
                {
                    RenderTableRow(null, OrderedVisibleColumns, alternate, empty: true);
                    alternate = !alternate;
                }
            }

            if (items.Length == 0)
            {
                Writer.Write("<tr>");
                Writer.Write("<td class=\"empty-grid-row\" colspan=\"{1}\">{0}</td>", GridRenderOptions.EmptyText,
                             OrderedVisibleColumns.Count() + 2);
                Writer.Write("</tr>");
            }
            else
            {
                RenderSummaryRow(items, OrderedVisibleColumns.ToArray());
            }

            Writer.Write("</tbody>");
            Writer.Write("</table>");

            RenderGroupGridState(groupOptions);

            RenderPager(paginationViewModel, GridGroupPageLinkClass, true);

            Writer.Write("</div>");
        }
Esempio n. 5
0
        public virtual IPagedList RenderTableBody(IQueryable <TModel> query)
        {
            Writer.Write("<tbody>");
            IPagedList paginateModel;
            var        sortColumns = OrderedVisibleColumns.Where(x => x.Value.SortDirection.HasValue).Select(x => x.Value).OrderBy(x => x.SortOrder).ToArray();

            if (IsGroupGrid)
            {
                var groupColumns = OrderedVisibleColumns.Where(x => x.Value.GroupKeyProperty != null && x.Value.GroupOrder.HasValue).OrderBy(x => x.Value.GroupOrder).ToArray();

                #region Инициализируем опции для группы

                var groupOptions = new GridGroupOptions
                {
                    GPage    = 1,
                    GroupKey = new Dictionary <string, object>(),
                    GColOpt  = new Dictionary <string, IDictionary <string, object> >()
                };

                foreach (var column in GridModel.Options.ColOpt.Where(x => x.Value.Any(c => c.Key == "so" || c.Key == "sd")))
                {
                    groupOptions.GColOpt[column.Key] = new Dictionary <string, object>();
                    foreach (var colOptions in column.Value)
                    {
                        groupOptions.GColOpt[column.Key][colOptions.Key] = colOptions.Value;
                    }
                }

                #endregion

                var groupQuery = query.GroupBy(groupColumns.ToDictionary(x => x.Value.GroupKeyProperty, x => x.Value.GroupSortDirection));

                var groupQueryCount = groupQuery.ToArray().Count();
                var page            = GridModel.Page == 0 ? 1 : GridModel.Page;
                if (page > (int)Math.Ceiling(((double)groupQueryCount) / GridModel.PageSize))
                {
                    page = 1;
                }
                var numberToSkip = (page - 1) * GridModel.PageSize;
                var items        = groupQuery.Skip(numberToSkip).Take(GridModel.PageSize).ToArray();

                paginateModel = new PagedListModel(page, GridModel.PageSize, groupQueryCount);

                var alternate   = false;
                var columnCount = OrderedVisibleColumns.Count();

                for (var i = 0; i < items.Length; i++)
                {
                    var item = items[i];
                    RenderGroupTableRow(groupColumns, item, alternate, columnCount, groupOptions);
                    alternate = !alternate;
                }

                if (GridModel.ShowEmptyRows)
                {
                    if (GridModel.ShowEmptyRows)
                    {
                        for (var i = items.Length; i < GridModel.PageSize; i++)
                        {
                            RenderGroupTableRow(groupColumns, null, alternate, columnCount, groupOptions, empty: true);
                            alternate = !alternate;
                        }
                    }
                }
                if (items.Length == 0)
                {
                    Writer.Write("<tr>");
                    Writer.Write("<td class=\"empty-grid-row\" colspan=\"{1}\">{0}</td>", GridRenderOptions.EmptyText, OrderedVisibleColumns.Count() + 2);
                    Writer.Write("</tr>");
                }
            }
            else
            {
                query = query.Sort(sortColumns.ToDictionary(x => x.SortProperty, x => x.SortDirection));
                var queryCount = query.Count();
                var page       = GridModel.Page == 0 ? 1 : GridModel.Page;
                if (page > (int)Math.Ceiling(((double)queryCount) / GridModel.PageSize))
                {
                    page = 1;
                }

                var numberToSkip = (page - 1) * GridModel.PageSize;
                var items        = query.Skip(numberToSkip).Take(GridModel.PageSize).ToArray();
                GridModel.PrepareSource(items);

                paginateModel = new PagedListModel(page, GridModel.PageSize, queryCount);
                var alternate = false;

                for (var i = 0; i < items.Length; i++)
                {
                    var item = items[i];
                    RenderTableRow(item, OrderedVisibleColumns, alternate);
                    alternate = !alternate;
                }

                if (GridModel.ShowEmptyRows)
                {
                    for (var i = items.Length; i < GridModel.PageSize; i++)
                    {
                        RenderTableRow(null, OrderedVisibleColumns, alternate, empty: true);
                        alternate = !alternate;
                    }
                }

                if (items.Length == 0)
                {
                    Writer.Write("<tr>");
                    Writer.Write("<td class=\"empty-grid-row\" colspan=\"{1}\">{0}</td>", GridRenderOptions.EmptyText, OrderedVisibleColumns.Count() + 2);
                    Writer.Write("</tr>");
                }
                else
                {
                    RenderSummaryRow(items, OrderedVisibleColumns.ToArray());
                }
            }

            Writer.Write("</tbody>");

            return(paginateModel);
        }
Esempio n. 6
0
        public virtual void Render(HtmlHelper htmlHelper, IQueryable <TModel> query)
        {
            _orderedVisibleColumns = GridModel.Columns.Where(c => c.Value.IsVisible).OrderBy(c => c.Value.Order).ToList();

            _isGroupGrid = _orderedVisibleColumns.Any(x => x.Value.GroupOrder.HasValue && x.Value.GroupKeyProperty != null);

            _htmlHelper = htmlHelper;

            _urlHelper = new UrlHelper(_htmlHelper.ViewContext.RequestContext);

            _writer = htmlHelper.ViewContext.Writer;

            _gridRenderOptions = GridModel.GridRenderOptions ?? new GridRenderOptions();

            var groupOptions = ModelHelper.GetModel <GridGroupOptions>(GridModel.Prefix, null, null, HtmlHelper.ViewContext.Controller.ValueProvider, HtmlHelper.ViewContext.Controller.ControllerContext);

            if (groupOptions != null && groupOptions.GroupKey != null && groupOptions.GroupKey.Any())
            {
                GridModel.MergeGridGroupOptions(groupOptions);

                var sortColumns  = OrderedVisibleColumns.Where(x => x.Value.SortDirection.HasValue).Select(x => x.Value).OrderBy(x => x.SortOrder).ToArray();
                var groupColumns = GridModel.Columns.Where(x => groupOptions.GroupKey.ContainsKey(x.Key));

                query = groupColumns.Aggregate(query, (current, column) => current.Where(column.Value.GroupKeyProperty, groupOptions.GroupKey[column.Key])).Sort(sortColumns.ToDictionary(x => x.SortProperty, x => x.SortDirection));

                var queryCount = query.Count();
                var page       = groupOptions.GPage == 0 ? 1 : groupOptions.GPage;

                if (page > (int)Math.Ceiling(((double)queryCount) / GridModel.PageSizeInGroup))
                {
                    page = 1;
                }
                var numberToSkip = (page - 1) * GridModel.PageSizeInGroup;
                var items        = query.Skip(numberToSkip).Take(GridModel.PageSizeInGroup).ToArray();
                GridModel.PrepareSource(items);

                var paginationModel = new PagedListModel(page, GridModel.PageSizeInGroup, queryCount);

                RenderGroupTable(items, groupOptions, paginationModel);
            }
            else
            {
                RenderGidContainerStart();

                RenderGroupingHeader();

                RenderTableStart();

                RenderTableHeader();

                var paginateModel = RenderTableBody(query);

                RenderTableEnd();

                RenderGridState();

                RenderPager(paginateModel, GridPageLinkClass, false);

                RenderGidContainerEnd();
            }
        }