Skip to content

Commit

Permalink
DataPager: disable links when not clickable (on last page or first page)
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Feb 25, 2024
1 parent ea78f4a commit 3449608
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/Framework/Framework/Controls/DataPager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,24 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context)

pagerBindings = gridViewDataSetBindingProvider.GetDataPagerCommands(this.GetDataContextType().NotNull(), dataSetBinding, commandType);

var enabled = GetValueOrBinding<bool>(EnabledProperty)!;
var globalEnabled = GetValueOrBinding<bool>(EnabledProperty)!;

ContentWrapper = CreateWrapperList();
Children.Add(ContentWrapper);

if (typeof(IPageableGridViewDataSet<IPagingFirstPageCapability>).IsAssignableFrom(dataSetType))
{
GoToFirstPageButton = CreateNavigationButton("««", FirstPageTemplate, enabled, pagerBindings.GoToFirstPage!, context);
GoToFirstPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding<bool>(pagerBindings.IsFirstPage.NotNull()));
var disabled = new ValueOrBinding<bool>(pagerBindings.IsFirstPage.NotNull());
GoToFirstPageButton = CreateNavigationButton("««", FirstPageTemplate, globalEnabled.And(disabled.Negate()), pagerBindings.GoToFirstPage!, context);
GoToFirstPageButton.CssClasses.Add(DisabledItemCssClass, disabled);
ContentWrapper.Children.Add(GoToFirstPageButton);
}

if (typeof(IPageableGridViewDataSet<IPagingPreviousPageCapability>).IsAssignableFrom(dataSetType))
{
GoToPreviousPageButton = CreateNavigationButton("«", PreviousPageTemplate, enabled, pagerBindings.GoToPreviousPage!, context);
GoToPreviousPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding<bool>(pagerBindings.IsFirstPage.NotNull()));
var disabled = new ValueOrBinding<bool>(pagerBindings.IsFirstPage.NotNull());
GoToPreviousPageButton = CreateNavigationButton("«", PreviousPageTemplate, globalEnabled.And(disabled.Negate()), pagerBindings.GoToPreviousPage!, context);
GoToPreviousPageButton.CssClasses.Add(DisabledItemCssClass, disabled);
ContentWrapper.Children.Add(GoToPreviousPageButton);
}

Expand All @@ -195,7 +197,7 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context)
var link = new LinkButton();
link.SetBinding(ButtonBase.ClickProperty, pagerBindings.GoToPage.NotNull());
link.SetBinding(ButtonBase.TextProperty, pagerBindings.PageNumberText.NotNull());
if (!true.Equals(enabled)) link.SetValue(LinkButton.EnabledProperty, enabled);
if (!true.Equals(globalEnabled)) link.SetValue(LinkButton.EnabledProperty, globalEnabled);
liTemplate.Children.Add(link);
if (!this.RenderLinkForCurrentPage)
{
Expand All @@ -216,15 +218,17 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context)

if (typeof(IPageableGridViewDataSet<IPagingNextPageCapability>).IsAssignableFrom(dataSetType))
{
GoToNextPageButton = CreateNavigationButton("»", NextPageTemplate, enabled, pagerBindings.GoToNextPage!, context);
GoToNextPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding<bool>(pagerBindings.IsLastPage.NotNull()));
var disabled = new ValueOrBinding<bool>(pagerBindings.IsLastPage.NotNull());
GoToNextPageButton = CreateNavigationButton("»", NextPageTemplate, globalEnabled.And(disabled.Negate()), pagerBindings.GoToNextPage!, context);
GoToNextPageButton.CssClasses.Add(DisabledItemCssClass, disabled);
ContentWrapper.Children.Add(GoToNextPageButton);
}

if (typeof(IPageableGridViewDataSet<IPagingLastPageCapability>).IsAssignableFrom(dataSetType))
{
GoToLastPageButton = CreateNavigationButton("»»", LastPageTemplate, enabled, pagerBindings.GoToLastPage!, context);
GoToLastPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding<bool>(pagerBindings.IsLastPage.NotNull()));
var disabled = new ValueOrBinding<bool>(pagerBindings.IsLastPage.NotNull());
GoToLastPageButton = CreateNavigationButton("»»", LastPageTemplate, globalEnabled.And(disabled.Negate()), pagerBindings.GoToLastPage!, context);
GoToLastPageButton.CssClasses.Add(DisabledItemCssClass, disabled);
ContentWrapper.Children.Add(GoToLastPageButton);
}
}
Expand Down

0 comments on commit 3449608

Please sign in to comment.