private static string GenerateLinks(this HtmlHelper helper, GridPagerProperties properties) { TagBuilder pagerDiv = new TagBuilder("div") { }; pagerDiv.MergeAttributes(new Dictionary<string, string> { { "class", "pager" } }); TagBuilder ulDiv = new TagBuilder("div"); ulDiv.MergeAttributes(new Dictionary<string, string> { { "class", "pagerItem" } }); TagBuilder ul = new TagBuilder("ul"); if (properties.PageCount > 1) { //create the previous tag if (properties.CurrentPageIndex > 1) { properties.LinkText = "<"; properties.RefPageIndex = properties.CurrentPageIndex - 1; //add previous tag ul.InnerHtml += GetNavItem(helper, properties).ToString(); } for (int page = 1; page <= properties.PageCount; page++) { //create paging tags properties.LinkText = page.ToString(); properties.RefPageIndex = page; //create tag TagBuilder tag = GetNavItem(helper, properties); if (page == properties.CurrentPageIndex) { tag.Attributes.Add("class", "selected"); } TagBuilder label = new TagBuilder("label") { InnerHtml = HttpUtility.HtmlEncode("...") }; label.MergeAttributes(new Dictionary<string, string> { { "text", "..." } }); if (properties.PageCount > 11) { if (properties.CurrentPageIndex < 7) { //beginning if (page < 9 || ((properties.PageCount - page) < 3)) ul.InnerHtml += tag.ToString(); else if (page == 10) ul.InnerHtml += label.ToString(); } else if (properties.CurrentPageIndex >= (properties.PageCount - 7)) { //end if (page < 2 || (page >= properties.PageCount - 9)) ul.InnerHtml += tag.ToString(); else if (page == 2) ul.InnerHtml += label.ToString(); } else { //middle if (page < 2) ul.InnerHtml += tag.ToString(); else if (page == 2) ul.InnerHtml += label.ToString(); else if ((page >= (properties.CurrentPageIndex - 4)) && (page <= (properties.CurrentPageIndex + 4))) ul.InnerHtml += tag.ToString(); else if (page == properties.CurrentPageIndex + 5) ul.InnerHtml += label.ToString(); else if (page >= properties.PageCount - 2) ul.InnerHtml += tag.ToString(); } } else ul.InnerHtml += tag.ToString(); } //create the next tag if (properties.CurrentPageIndex < properties.PageCount) { properties.LinkText = ">"; properties.RefPageIndex = properties.CurrentPageIndex + 1; //add previous tag ul.InnerHtml += GetNavItem(helper, properties).ToString(); } } ulDiv.InnerHtml += ul; pagerDiv.InnerHtml += ulDiv; // create the total items tag TagBuilder countDiv = new TagBuilder("div") { InnerHtml = String.Format("{0} items", properties.RecordCount) }; countDiv.MergeAttributes(new Dictionary<string, string> { { "class", "totalrecords" }, { "id", "grid_totalrecords" } }); pagerDiv.InnerHtml += countDiv.ToString(); return pagerDiv.ToString(); }
public static string GridPagerWithoutAjax(this HtmlHelper helper, GridPagerProperties properties) { return GenerateLinks(helper, properties); }
public static string GridPager(this AjaxHelper helper, GridPagerProperties properties) { return GenerateLinks(helper, properties); }
public static TagBuilder GetNavItem(this HtmlHelper html, GridPagerProperties properties) { UrlHelper urlHelper = ((Controller)html.ViewContext.Controller).Url; string url = ""; url = urlHelper.Action(properties.ActionName, properties.Controller, new { LoaiAnh = properties.TransferValue, page = properties.RefPageIndex }); TagBuilder actionLink = new TagBuilder("a"); actionLink.SetInnerText(properties.LinkText); actionLink.MergeAttributes(new Dictionary<string, string> { { "href", url } }); TagBuilder linkTag = new TagBuilder("li") { InnerHtml = actionLink.ToString() }; return linkTag; }
public static TagBuilder GetNavItem(this AjaxHelper ajax, GridPagerProperties properties) { MvcHtmlString htmlTemplate = null; switch (properties.TypeOfParam) { case EnumTypeOfParam.DEFAULT: htmlTemplate = ajax.ActionLink(properties.LinkText, properties.ActionName, properties.Controller, new { page = properties.RefPageIndex }, new AjaxOptions { UpdateTargetId = properties.UpdateTargetId }); break; case EnumTypeOfParam.ANH: htmlTemplate = ajax.ActionLink(properties.LinkText, properties.ActionName, properties.Controller, new { page = properties.RefPageIndex, loaianh = properties.TransferValue }, new AjaxOptions { UpdateTargetId = properties.UpdateTargetId }); break; } TagBuilder linkTag = new TagBuilder("li") { InnerHtml = htmlTemplate.ToHtmlString() }; return linkTag; }