Beispiel #1
0
        private static string CustomGenerateClassName(PaginationSize size, PaginationAlignment align)
        {
            var className = "pagination";

            switch (size)
            {
            case PaginationSize.Large:
                className += " pagination-large";
                break;

            case PaginationSize.Small:
                className += " pagination-small";
                break;

            case PaginationSize.Mini:
                className += " pagination-mini";
                break;
            }

            switch (align)
            {
            case PaginationAlignment.Centered:
                className += " pagination-centered";
                break;

            case PaginationAlignment.Right:
                className += " pagination-right";
                break;
            }

            return(className);
        }
Beispiel #2
0
        public static MvcHtmlString PaginationFor <TModel>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, PaginationModel> > expression, PaginationSize size, PaginationAlignment align)
        {
            var className          = GenerateClassName(size, align);
            var listHtmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(new { @class = className });

            return(htmlHelper.PaginationInternal(expression, listHtmlAttributes));
        }
         /// <summary>
        ///  Private method that generates the UI Pagination Component for all public overload methods
        /// </summary>
        /// <param name="baseUrl">Page Url</param>
        /// <param name="count">Model total count</param>
        /// <param name="pageSize">Number of items to display per page</param>
        /// <param name="page">Current Page</param>
        /// <param name="pageSpread">Max Number of page links to display</param>
        /// <param name="cssClass">Component css class attribute value</param>
        /// <param name="tagName">custom tag name</param>
        /// <returns>MvcHtmlString</returns>
        private IHtmlString uiPagination(string baseUrl, int count, int pageSize, int page, int pageSpread, string cssClass, string tagName, PaginationAlignment alignment)
        {

            var element = "";
            tagName = tagName ?? "ui-pagination";
            var endTag = "</" + tagName + ">";
            if (cssClass == null)
            {
                if (alignment == PaginationAlignment.Left)
                {
                    element = "<" + tagName + ">";
                }
                else
                {
                    element = "<" + tagName + " class='center'>";
                }
            }
            else
            {
                if (alignment == PaginationAlignment.Left)
                {
                    element = "<" + tagName + " class='" + cssClass + "'>";
                }
                else
                {
                    element = "<" + tagName + " class='" + cssClass + " center'>";
                }
            }

            var prevPage = new PageLink();
            prevPage.CssClass = "hide";
            var nextPage = new PageLink();
            nextPage.CssClass = "hide";
            int pageCount = count / pageSize;
            int remainder = count % pageSize;
            if (pageCount < 1)
            {
                pageCount = 1;
            }
            else if (remainder > 0)
            {
                pageCount++;
            }

            element += "<div class='page-info'>Page";
            element += "<span class='page-no'> " + page + "</span> of <span class='page-count'>" + pageCount + "</span>";
            element += "</div>";
            element += "<ul class='right'>";

            //prev
            if (page > 1)
            {
                prevPage.CssClass = "";
                prevPage.Url = pageUrl(baseUrl, page - 1);
                element += "<li><a href='" + prevPage.Url + "'>prev</a></li>";
            }

            //pages
            if (pageCount > 1)
            {
                var pages = pageLinks(baseUrl, page, pageCount, pageSpread);
                foreach (PageLink p in pages)
                {
                    element += "<li><a class='" + p.Active + "' href='" + p.Url + "'>" + p.Page + "</a></li>";
                }
            }

            //next
            if (page < pageCount)
            {
                nextPage.CssClass = "";
                nextPage.Url = pageUrl(baseUrl, page + 1);
                element += "<li><a href='" + nextPage.Url + "'>next</a></li>";
            }


            element += "</ul>" + endTag;


            return new MvcHtmlString(element);

        }
 /// <summary>
 /// UI Pagination Component method overload
 /// </summary>
 /// <param name="baseUrl"></param>
 /// <param name="count"></param>
 /// <param name="pageSize"></param>
 /// <param name="page"></param>
 /// <param name="pageSpread"></param>
 /// <param name="cssClass"></param>
 /// <param name="tagName"></param>
 /// <param name="alignment"></param>
 /// <returns></returns>
 public IHtmlString UIPagination(string baseUrl, int count, int pageSize, int page, int pageSpread, string cssClass, string tagName, PaginationAlignment alignment)
 {
     return uiPagination(baseUrl, count, pageSize, page, pageSpread, cssClass, tagName, alignment);
 }
 /// <summary>
 /// UI Pagination Component method overload
 /// </summary>
 /// <param name="pagination"></param>
 /// <param name="alignment"></param>
 /// <returns></returns>
 public IHtmlString UIPagination(Pagination pagination, PaginationAlignment alignment)
 {
     return uiPagination(pagination.BaseUrl, pagination.Count, pagination.PageSize, pagination.Page, pagination.PageSpread, pagination.CssClass, pagination.TagName, alignment);
 }