public override void Process(TagHelperContext context, TagHelperOutput output) { if (PagingModel == null) { // allow for passing in the settings separately PagingModel = new PaginationSettings(); PagingModel.CurrentPage = PageNumber; PagingModel.ItemsPerPage = PageSize; PagingModel.TotalItems = TotalItems; PagingModel.MaxPagerItems = MaxPagerItems; PagingModel.SuppressEmptyNextPrev = SuppressEmptyNextPrev; PagingModel.SuppressInActiveFirstLast = SuppressInActiveFirstLast; } if (ShowFirstLast) { PagingModel.ShowFirstLast = true; } if (!ShowNumbered) { PagingModel.ShowNumbered = false; } if (UseReverseIncrement) { PagingModel.UseReverseIncrement = true; if (SuppressEmptyNextPrev) { PagingModel.SuppressEmptyNextPrev = true; } } int totalPages = (int)Math.Ceiling(PagingModel.TotalItems / (double)PagingModel.ItemsPerPage); // don't render if only 1 page if (SuppressEmptyPager && (totalPages <= 1)) { output.SuppressOutput(); return; } //change the cs-pager element into a ul output.TagName = "ul"; //prepare things needed by generatpageeurl function urlHelper = urlHelperFactory.GetUrlHelper(actionContextAccesor.ActionContext); List <PaginationLink> links = linkBuilder.BuildPaginationLinks( PagingModel, GeneratePageUrl, FirstPageText, FirstPageTitle, PreviousPageText, PreviousPageTitle, NextPageText, NextPageTitle, LastPageText, LastPageTitle, "..."); foreach (PaginationLink link in links) { var li = new TagBuilder("li"); if (link.IsCurrent) { li.AddCssClass(LiCurrentCssClass); } else { if (!link.Active) { li.AddCssClass(LiNonActiveCssClass); } else { if (!string.IsNullOrWhiteSpace(LiOtherCssClass)) { li.AddCssClass(LiOtherCssClass); } } } if (link.Text == PreviousPageText && !string.IsNullOrWhiteSpace(PreviousPageHtml)) { li.InnerHtml.AppendHtml(PreviousPageHtml); } else if (link.Text == NextPageText && !string.IsNullOrWhiteSpace(NextPageHtml)) { li.InnerHtml.AppendHtml(NextPageHtml); } else { if (!link.IsCurrent && link.Active) { var a = new TagBuilder("a"); if (!string.IsNullOrWhiteSpace(LinkOtherCssClass)) { a.AddCssClass(LinkOtherCssClass); } if (link.Active && (link.Url.Length > 0)) { a.MergeAttribute("href", link.Url); } else { a.MergeAttribute("href", "#"); } if (link.Text == "«") { a.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { a.InnerHtml.AppendHtml("»"); } else if (link.Text.Contains('<') && link.Text.Contains('>')) { //if text is an html formatted icon and contains a <tag> //ex. <span class='fa fa-chevron-right'></span> a.InnerHtml.AppendHtml(link.Text); } else { // if text should be html encoded a.InnerHtml.Append(link.Text); } if (link.Title.Length > 0) { a.MergeAttribute("title", link.Title); } if (AjaxTarget.Length > 0) { a.MergeAttribute("data-ajax", "true"); a.MergeAttribute("data-ajax-mode", AjaxMode); a.MergeAttribute("data-ajax-update", AjaxTarget); if (AjaxSuccess.Length > 0) { a.MergeAttribute("data-ajax-success", AjaxSuccess); } if (AjaxFailure.Length > 0) { a.MergeAttribute("data-ajax-failure", AjaxFailure); } if (AjaxBegin.Length > 0) { a.MergeAttribute("data-ajax-begin", AjaxBegin); } if (AjaxComplete.Length > 0) { a.MergeAttribute("data-ajax-complete", AjaxComplete); } if (AjaxLoading.Length > 0) { a.MergeAttribute("data-ajax-loading", AjaxLoading); } if (AjaxLoadingDuration.Length > 0) { a.MergeAttribute("data-ajax-loading-duration", AjaxLoadingDuration); } } li.InnerHtml.AppendHtml(a); } else { // current or not active var span = new TagBuilder("span"); if (!string.IsNullOrWhiteSpace(LinkCurrentCssClass)) { span.AddCssClass(LinkCurrentCssClass); } if (link.Text == "«") { span.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { span.InnerHtml.AppendHtml("»"); } else if (link.Text.Contains('<') && link.Text.Contains('>')) { //if text is an html formatted icon and contains a <tag> //ex. <span class='fa fa-chevron-right'></span> span.InnerHtml.AppendHtml(link.Text); } else { // if text should be html encoded span.InnerHtml.Append(link.Text); } li.InnerHtml.AppendHtml(span); } } output.Content.AppendHtml(li); } output.Attributes.Clear(); output.Attributes.Add("class", UlCssClass); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (PagingModel == null) { output.SuppressOutput(); return; } int totalPages = (int)Math.Ceiling(PagingModel.TotalItems / (double)PagingModel.ItemsPerPage); // don't render if only 1 page if (totalPages <= 1) { output.SuppressOutput(); return; } //change the bs-pager element into a ul output.TagName = "ul"; string querySeparator; //prepare things needed by generatpageeurl function TagBuilder linkTemplate = GenerateLinkTemplate(); baseHref = linkTemplate.Attributes["href"]; querySeparator = baseHref.Contains("?") ? "&" : "?"; baseHref = baseHref + querySeparator + PageNumberParam + "="; List <PaginationLink> links = linkBuilder.BuildPaginationLinks( PagingModel, GeneratePageUrl, FirstPageText, FirstPageTitle, PreviousPageText, PreviousPageTitle, NextPageText, NextPageTitle, LastPageText, LastPageTitle, "..."); foreach (PaginationLink link in links) { var li = new TagBuilder("li"); if (link.IsCurrent) { li.AddCssClass(LiCurrentCssClass); } if (!link.Active) { li.AddCssClass(LiNonActiveCssClass); } var a = new TagBuilder("a"); if (link.Url.Length > 0) { a.MergeAttribute("href", link.Url); } else { a.MergeAttribute("href", "#"); } if (link.Text == "«") { //a.InnerHtml = "«"; a.InnerHtml.AppendEncoded("«"); } else if (link.Text == "»") { //a.InnerHtml = "»"; a.InnerHtml.AppendEncoded("»"); } else { a.InnerHtml.Append(link.Text); } if (link.Title.Length > 0) { a.MergeAttribute("title", link.Title); } if (AjaxTarget.Length > 0) { a.MergeAttribute("data-ajax", "true"); a.MergeAttribute("data-ajax-mode", AjaxMode); a.MergeAttribute("data-ajax-update", AjaxTarget); } li.InnerHtml.Append(a); output.Content.Append(li); } output.Attributes.Clear(); output.Attributes.Add("class", UlCssClass); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (PagingModel == null) { // allow for passing in the settings separately PagingModel = new PaginationSettings(); PagingModel.CurrentPage = PageNumber; PagingModel.ItemsPerPage = PageSize; PagingModel.TotalItems = TotalItems; PagingModel.MaxPagerItems = MaxPagerItems; PagingModel.SuppressEmptyNextPrev = SuppressEmptyNextPrev; PagingModel.SuppressInActiveFirstLast = SuppressInActiveFirstLast; } if (ShowFirstLast) { PagingModel.ShowFirstLast = true; } if (!ShowNumbered) { PagingModel.ShowNumbered = false; } if (UseReverseIncrement) { PagingModel.UseReverseIncrement = true; if (SuppressEmptyNextPrev) { PagingModel.SuppressEmptyNextPrev = true; } } int totalPages = (int)Math.Ceiling(PagingModel.TotalItems / (double)PagingModel.ItemsPerPage); // don't render if only 1 page if (totalPages <= 1) { output.SuppressOutput(); return; } //change the cs-pager element into a ul output.TagName = "ul"; string querySeparator; //prepare things needed by generatpageeurl function TagBuilder linkTemplate = GenerateLinkTemplate(); baseHref = linkTemplate.Attributes["href"] ?? string.Empty; querySeparator = baseHref.Contains("?") ? "&" : "?"; baseHref = baseHref + querySeparator + PageNumberParam + "="; List <PaginationLink> links = linkBuilder.BuildPaginationLinks( PagingModel, GeneratePageUrl, FirstPageText, FirstPageTitle, PreviousPageText, PreviousPageTitle, NextPageText, NextPageTitle, LastPageText, LastPageTitle, "..."); foreach (PaginationLink link in links) { var li = new TagBuilder("li"); if (link.IsCurrent) { li.AddCssClass(LiCurrentCssClass); } if (!link.Active) { li.AddCssClass(LiNonActiveCssClass); } var a = new TagBuilder("a"); if (link.Active && (link.Url.Length > 0)) { a.MergeAttribute("href", link.Url); } else { a.MergeAttribute("href", "#"); } if (link.Text == "«") { a.InnerHtml.AppendHtml("«"); } else if (link.Text == "»") { a.InnerHtml.AppendHtml("»"); } else { a.InnerHtml.Append(link.Text); } if (link.Title.Length > 0) { a.MergeAttribute("title", link.Title); } if (AjaxTarget.Length > 0) { a.MergeAttribute("data-ajax", "true"); a.MergeAttribute("data-ajax-mode", AjaxMode); a.MergeAttribute("data-ajax-update", AjaxTarget); if (AjaxSuccess.Length > 0) { a.MergeAttribute("data-ajax-success", AjaxSuccess); } if (AjaxFailure.Length > 0) { a.MergeAttribute("data-ajax-failure", AjaxFailure); } } li.InnerHtml.AppendHtml(a); output.Content.AppendHtml(li); } output.Attributes.Clear(); output.Attributes.Add("class", UlCssClass); }