Example #1
0
        /// <summary>
        ///     Gets the base page HTML.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="gridName">Name of the grid.</param>
        /// <param name="grid">The grid.</param>
        /// <param name="pageParameters">The page parameters.</param>
        /// <returns>System.String.</returns>
        /// TODO Edit XML Comment Template for GetBasePageHtml
        public string GetBasePageHtml(
            HtmlHelper helper,
            string gridName,
            IMvcGridDefinition grid,
            object pageParameters)
        {
            var preload = "";

            if (grid.QueryOnPageLoad &&
                grid.PreloadData)
            {
                try
                {
                    preload = RenderPreloadedGridHtml(
                        helper,
                        grid,
                        gridName,
                        pageParameters);
                }
                catch (Exception ex)
                {
                    var showDetails = ConfigUtility
                                      .GetShowErrorDetailsSetting();

                    if (showDetails)
                    {
                        var detail = "<div class='alert alert-danger'>";

                        detail += HttpUtility.HtmlEncode(ex.ToString())
                                  .Replace("\r\n", "<br />");

                        detail += "</div>";
                        preload = detail;
                    }
                    else
                    {
                        preload = grid.ErrorMessageHtml;
                    }
                }
            }

            var baseGridHtml =
                MvcGridHtmlGenerator.GenerateBasePageHtml(
                    gridName,
                    grid,
                    pageParameters);

            baseGridHtml = baseGridHtml.Replace("%%PRELOAD%%", preload);

            var containerRenderingModel = new ContainerRenderingModel
            {
                InnerHtmlBlock = baseGridHtml
            };

            var html =
                RenderContainerHtml(helper, grid, containerRenderingModel);

            return(html);
        }
Example #2
0
        /// <summary>
        ///     Preps the model.
        /// </summary>
        /// <param name="totalRecords">The total records.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="gridContext">The grid context.</param>
        /// <returns>RenderingModel.</returns>
        /// TODO Edit XML Comment Template for PrepModel
        private static RenderingModel PrepModel(
            int?totalRecords,
            List <Row> rows,
            GridContext gridContext)
        {
            var model = new RenderingModel
            {
                HandlerPath = HtmlUtility.GetHandlerPath(),
                TableHtmlId = HtmlUtility.GetTableHtmlId(gridContext.GridName)
            };

            PrepColumns(gridContext, model);
            model.Rows = rows;

            if (model.Rows.Count == 0)
            {
                model.NoResultsMessage =
                    gridContext.GridDefinition.NoResultsMessage;
            }

            model.NextButtonCaption = gridContext.GridDefinition
                                      .NextButtonCaption;

            model.PreviousButtonCaption = gridContext.GridDefinition
                                          .PreviousButtonCaption;

            model.SummaryMessage = gridContext.GridDefinition.SummaryMessage;

            model.ProcessingMessage = gridContext.GridDefinition
                                      .ProcessingMessage;

            model.PagingModel = null;

            if (gridContext.QueryOptions.ItemsPerPage.HasValue)
            {
                model.PagingModel = new PagingModel();

                if (gridContext.QueryOptions.PageIndex != null)
                {
                    var currentPageIndex =
                        gridContext.QueryOptions.PageIndex.Value;

                    if (totalRecords != null)
                    {
                        model.PagingModel.TotalRecords = totalRecords.Value;
                    }

                    model.PagingModel.FirstRecord =
                        currentPageIndex
                        * gridContext.QueryOptions.ItemsPerPage.Value
                        + 1;

                    if (model.PagingModel.FirstRecord
                        > model.PagingModel.TotalRecords)
                    {
                        model.PagingModel.FirstRecord =
                            model.PagingModel.TotalRecords;
                    }

                    model.PagingModel.LastRecord =
                        model.PagingModel.FirstRecord
                        + gridContext.QueryOptions.ItemsPerPage.Value
                        - 1;

                    if (model.PagingModel.LastRecord
                        > model.PagingModel.TotalRecords)
                    {
                        model.PagingModel.LastRecord =
                            model.PagingModel.TotalRecords;
                    }

                    model.PagingModel.CurrentPage = currentPageIndex + 1;
                }

                var numberOfPagesD = (model.PagingModel.TotalRecords + 0.0)
                                     / (gridContext.QueryOptions.ItemsPerPage
                                        .Value
                                        + 0.0);

                model.PagingModel.NumberOfPages =
                    (int)Math.Ceiling(numberOfPagesD);

                for (var i = 1; i <= model.PagingModel.NumberOfPages; i++)
                {
                    model.PagingModel.PageLinks.Add(
                        i,
                        HtmlUtility.MakeGotoPageLink(gridContext.GridName, i));
                }
            }

            model.ClientDataTransferHtmlBlock = MvcGridHtmlGenerator
                                                .GenerateClientDataTransferHtml(gridContext);

            return(model);
        }