Replace WebGridBootstrapPager
Improve Leaf details page
This commit is contained in:
@@ -22,12 +22,12 @@ namespace LeafWeb.WebCms.Utility
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetButtonDisabled(this ViewDataDictionary vdd)
|
||||
public static void SetCssDisabled(this ViewDataDictionary vdd)
|
||||
{
|
||||
vdd.AddCssClass("disabled");
|
||||
}
|
||||
|
||||
public static bool IsButtonDisabled(this ViewDataDictionary vdd)
|
||||
public static bool IsCssDisabled(this ViewDataDictionary vdd)
|
||||
{
|
||||
return vdd.ContainsKey(KeyName) && ((string[]) vdd[KeyName]).Contains("disabled");
|
||||
}
|
||||
|
||||
@@ -12,16 +12,22 @@ namespace LeafWeb.WebCms.Utility
|
||||
public static HelperResult PagerList(
|
||||
this WebGrid webGrid,
|
||||
WebGridPagerModes mode = WebGridPagerModes.NextPrevious | WebGridPagerModes.Numeric,
|
||||
string firstText = null,
|
||||
string previousText = null,
|
||||
string nextText = null,
|
||||
string lastText = null,
|
||||
string firstText = "First",
|
||||
string previousText = "Prev",
|
||||
string nextText = "Next",
|
||||
string lastText = "Last",
|
||||
int numericLinksCount = 5,
|
||||
string paginationStyle = null)
|
||||
{
|
||||
return PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount, paginationStyle, explicitlyCalled: true);
|
||||
return PagerList(webGrid, mode, firstText, previousText, nextText, lastText, numericLinksCount,
|
||||
paginationStyle, true);
|
||||
}
|
||||
|
||||
/* bootstrap pagination classes */
|
||||
private const string ulClass = "pagination";
|
||||
private const string liClass = "page-item";
|
||||
private const string aClass = "page-link";
|
||||
|
||||
private static HelperResult PagerList(
|
||||
WebGrid webGrid,
|
||||
WebGridPagerModes mode,
|
||||
@@ -33,150 +39,110 @@ namespace LeafWeb.WebCms.Utility
|
||||
string paginationStyle,
|
||||
bool explicitlyCalled)
|
||||
{
|
||||
|
||||
int currentPage = webGrid.PageIndex;
|
||||
int totalPages = webGrid.PageCount;
|
||||
int lastPage = totalPages - 1;
|
||||
var currentPage = webGrid.PageIndex;
|
||||
var totalPages = webGrid.PageCount;
|
||||
var lastPage = totalPages - 1;
|
||||
|
||||
var ul = new TagBuilder("ul");
|
||||
ul.AddCssClass(ulClass);
|
||||
ul.AddCssClass(paginationStyle);
|
||||
|
||||
var li = new List<TagBuilder>();
|
||||
|
||||
if(webGrid.TotalRowCount <= webGrid.PageCount)
|
||||
{
|
||||
return new HelperResult(writer =>
|
||||
{
|
||||
writer.Write(string.Empty);
|
||||
});
|
||||
}
|
||||
if (webGrid.TotalRowCount <= webGrid.PageCount)
|
||||
return new HelperResult(writer => writer.Write(string.Empty));
|
||||
|
||||
if(ModeEnabled(mode, WebGridPagerModes.FirstLast))
|
||||
if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && totalPages > 1)
|
||||
{
|
||||
if(String.IsNullOrEmpty(firstText))
|
||||
{
|
||||
firstText = "First";
|
||||
}
|
||||
|
||||
var part = new TagBuilder("li")
|
||||
{
|
||||
InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(0), firstText)
|
||||
};
|
||||
part.AddCssClass(liClass);
|
||||
|
||||
if(currentPage == 0)
|
||||
{
|
||||
part.MergeAttribute("class", "disabled");
|
||||
}
|
||||
if (currentPage == 0) part.AddCssClass("disabled");
|
||||
|
||||
li.Add(part);
|
||||
|
||||
}
|
||||
|
||||
if(ModeEnabled(mode, WebGridPagerModes.NextPrevious))
|
||||
if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && totalPages > 1)
|
||||
{
|
||||
if(String.IsNullOrEmpty(previousText))
|
||||
{
|
||||
previousText = "Prev";
|
||||
}
|
||||
|
||||
int page = currentPage == 0 ? 0 : currentPage - 1;
|
||||
var page = currentPage == 0 ? 0 : currentPage - 1;
|
||||
|
||||
var part = new TagBuilder("li")
|
||||
{
|
||||
InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), previousText)
|
||||
};
|
||||
part.AddCssClass(liClass);
|
||||
|
||||
if(currentPage == 0)
|
||||
{
|
||||
part.MergeAttribute("class", "disabled");
|
||||
}
|
||||
if (currentPage == 0) part.AddCssClass("disabled");
|
||||
|
||||
li.Add(part);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(ModeEnabled(mode, WebGridPagerModes.Numeric) && (totalPages > 1))
|
||||
if (ModeEnabled(mode, WebGridPagerModes.Numeric) && totalPages > 1)
|
||||
{
|
||||
int last = currentPage + (numericLinksCount / 2);
|
||||
int first = last - numericLinksCount + 1;
|
||||
if(last > lastPage)
|
||||
var last = currentPage + numericLinksCount / 2;
|
||||
var first = last - numericLinksCount + 1;
|
||||
if (last > lastPage)
|
||||
{
|
||||
first -= last - lastPage;
|
||||
last = lastPage;
|
||||
}
|
||||
if(first < 0)
|
||||
|
||||
if (first < 0)
|
||||
{
|
||||
last = Math.Min(last + (0 - first), lastPage);
|
||||
first = 0;
|
||||
}
|
||||
for(int i = first; i <= last; i++)
|
||||
{
|
||||
|
||||
for (var i = first; i <= last; i++)
|
||||
{
|
||||
var pageText = (i + 1).ToString(CultureInfo.InvariantCulture);
|
||||
var part = new TagBuilder("li")
|
||||
{
|
||||
InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(i), pageText)
|
||||
};
|
||||
part.AddCssClass(liClass);
|
||||
|
||||
if(i == currentPage)
|
||||
{
|
||||
part.MergeAttribute("class", "active");
|
||||
}
|
||||
if (i == currentPage) part.AddCssClass("active");
|
||||
|
||||
li.Add(part);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(ModeEnabled(mode, WebGridPagerModes.NextPrevious))
|
||||
if (ModeEnabled(mode, WebGridPagerModes.NextPrevious) && totalPages > 1)
|
||||
{
|
||||
if(String.IsNullOrEmpty(nextText))
|
||||
{
|
||||
nextText = "Next";
|
||||
}
|
||||
|
||||
int page = currentPage == lastPage ? lastPage : currentPage + 1;
|
||||
var page = currentPage == lastPage ? lastPage : currentPage + 1;
|
||||
|
||||
var part = new TagBuilder("li")
|
||||
{
|
||||
InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(page), nextText)
|
||||
};
|
||||
part.AddCssClass(liClass);
|
||||
|
||||
if(currentPage == lastPage)
|
||||
{
|
||||
part.MergeAttribute("class", "disabled");
|
||||
}
|
||||
if (currentPage == lastPage) part.AddCssClass("disabled");
|
||||
|
||||
li.Add(part);
|
||||
|
||||
}
|
||||
|
||||
if(ModeEnabled(mode, WebGridPagerModes.FirstLast))
|
||||
if (ModeEnabled(mode, WebGridPagerModes.FirstLast) && totalPages > 1)
|
||||
{
|
||||
if(String.IsNullOrEmpty(lastText))
|
||||
{
|
||||
lastText = "Last";
|
||||
}
|
||||
|
||||
var part = new TagBuilder("li")
|
||||
{
|
||||
InnerHtml = GridLink(webGrid, webGrid.GetPageUrl(lastPage), lastText)
|
||||
};
|
||||
|
||||
if(currentPage == lastPage)
|
||||
{
|
||||
part.MergeAttribute("class", "disabled");
|
||||
}
|
||||
if (currentPage == lastPage)
|
||||
part.AddCssClass("disabled");
|
||||
|
||||
li.Add(part);
|
||||
|
||||
}
|
||||
|
||||
ul.InnerHtml = string.Join("", li);
|
||||
|
||||
var html = "";
|
||||
if(explicitlyCalled && webGrid.IsAjaxEnabled)
|
||||
if (explicitlyCalled && webGrid.IsAjaxEnabled)
|
||||
{
|
||||
var span = new TagBuilder("span");
|
||||
span.MergeAttribute("data-swhgajax", "true");
|
||||
@@ -185,36 +151,29 @@ namespace LeafWeb.WebCms.Utility
|
||||
|
||||
span.InnerHtml = ul.ToString();
|
||||
html = span.ToString();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
html = ul.ToString();
|
||||
}
|
||||
|
||||
return new HelperResult(writer =>
|
||||
{
|
||||
writer.Write(html);
|
||||
});
|
||||
return new HelperResult(writer => writer.Write(html));
|
||||
}
|
||||
|
||||
private static String GridLink(WebGrid webGrid, string url, string text)
|
||||
private static string GridLink(WebGrid webGrid, string url, string text)
|
||||
{
|
||||
TagBuilder builder = new TagBuilder("a");
|
||||
var builder = new TagBuilder("a");
|
||||
builder.SetInnerText(text);
|
||||
builder.MergeAttribute("href", url);
|
||||
if(webGrid.IsAjaxEnabled)
|
||||
{
|
||||
builder.AddCssClass(aClass);
|
||||
if (webGrid.IsAjaxEnabled)
|
||||
builder.MergeAttribute("data-swhglnk", "true");
|
||||
}
|
||||
return builder.ToString(TagRenderMode.Normal);
|
||||
}
|
||||
|
||||
|
||||
private static bool ModeEnabled(WebGridPagerModes mode, WebGridPagerModes modeCheck)
|
||||
{
|
||||
return (mode & modeCheck) == modeCheck;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user