From 34496081e59f3c502031224f67072ab3b4dd1ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Standa=20Luke=C5=A1?= Date: Sun, 25 Feb 2024 18:31:30 +0100 Subject: [PATCH] DataPager: disable links when not clickable (on last page or first page) --- src/Framework/Framework/Controls/DataPager.cs | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Framework/Framework/Controls/DataPager.cs b/src/Framework/Framework/Controls/DataPager.cs index 1d85221e90..62fda9d242 100644 --- a/src/Framework/Framework/Controls/DataPager.cs +++ b/src/Framework/Framework/Controls/DataPager.cs @@ -166,22 +166,24 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context) pagerBindings = gridViewDataSetBindingProvider.GetDataPagerCommands(this.GetDataContextType().NotNull(), dataSetBinding, commandType); - var enabled = GetValueOrBinding(EnabledProperty)!; + var globalEnabled = GetValueOrBinding(EnabledProperty)!; ContentWrapper = CreateWrapperList(); Children.Add(ContentWrapper); if (typeof(IPageableGridViewDataSet).IsAssignableFrom(dataSetType)) { - GoToFirstPageButton = CreateNavigationButton("««", FirstPageTemplate, enabled, pagerBindings.GoToFirstPage!, context); - GoToFirstPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding(pagerBindings.IsFirstPage.NotNull())); + var disabled = new ValueOrBinding(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).IsAssignableFrom(dataSetType)) { - GoToPreviousPageButton = CreateNavigationButton("«", PreviousPageTemplate, enabled, pagerBindings.GoToPreviousPage!, context); - GoToPreviousPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding(pagerBindings.IsFirstPage.NotNull())); + var disabled = new ValueOrBinding(pagerBindings.IsFirstPage.NotNull()); + GoToPreviousPageButton = CreateNavigationButton("«", PreviousPageTemplate, globalEnabled.And(disabled.Negate()), pagerBindings.GoToPreviousPage!, context); + GoToPreviousPageButton.CssClasses.Add(DisabledItemCssClass, disabled); ContentWrapper.Children.Add(GoToPreviousPageButton); } @@ -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) { @@ -216,15 +218,17 @@ protected virtual void DataBind(Hosting.IDotvvmRequestContext context) if (typeof(IPageableGridViewDataSet).IsAssignableFrom(dataSetType)) { - GoToNextPageButton = CreateNavigationButton("»", NextPageTemplate, enabled, pagerBindings.GoToNextPage!, context); - GoToNextPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding(pagerBindings.IsLastPage.NotNull())); + var disabled = new ValueOrBinding(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).IsAssignableFrom(dataSetType)) { - GoToLastPageButton = CreateNavigationButton("»»", LastPageTemplate, enabled, pagerBindings.GoToLastPage!, context); - GoToLastPageButton.CssClasses.Add(DisabledItemCssClass, new ValueOrBinding(pagerBindings.IsLastPage.NotNull())); + var disabled = new ValueOrBinding(pagerBindings.IsLastPage.NotNull()); + GoToLastPageButton = CreateNavigationButton("»»", LastPageTemplate, globalEnabled.And(disabled.Negate()), pagerBindings.GoToLastPage!, context); + GoToLastPageButton.CssClasses.Add(DisabledItemCssClass, disabled); ContentWrapper.Children.Add(GoToLastPageButton); } }