Skip to content

Commit

Permalink
DataPager: returned client-side data context change
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Oct 7, 2023
1 parent ac7f0f7 commit dfa0471
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/Framework/Framework/Controls/DataPager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequest
var loadDataExpression = KnockoutHelper.GenerateClientPostbackLambda("LoadData", loadData, this, new PostbackScriptOptions(elementAccessor: "$element", koContext: CodeParameterAssignment.FromIdentifier("$context")));
helperBinding.Add("loadData", loadDataExpression);
}
writer.AddKnockoutDataBind("dotvvm-gridviewdataset", helperBinding.ToString());
writer.WriteKnockoutDataBindComment("dotvvm-gridviewdataset", helperBinding.ToString());

// If Visible property was set to something, it will be overwritten by this. TODO: is it how it should behave?
if (HideWhenOnlyOnePage)
Expand All @@ -295,7 +295,7 @@ protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequest
writer.AddKnockoutDataBind("visible", $"({dataSetBinding}).PagingOptions().PagesCount() > 1");
}

// writer.AddKnockoutDataBind("with", this, DataSetProperty, renderEvenInServerRenderingMode: true);
writer.AddKnockoutDataBind("with", this, DataSetProperty, renderEvenInServerRenderingMode: true);


if (GetValueBinding(EnabledProperty) is IValueBinding enabledBinding)
Expand Down Expand Up @@ -330,15 +330,15 @@ protected virtual void AddKnockoutActiveCssDataBind(IHtmlWriter writer, IDotvvmR
protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
{
AddItemCssClass(writer, context);
AddKnockoutDisabledCssDataBind(writer, context, "$gridViewDataSetHelper.dataSet.PagingOptions().IsFirstPage()");
AddKnockoutDisabledCssDataBind(writer, context, "PagingOptions().IsFirstPage()");
GoToFirstPageButton!.Render(writer, context);

AddItemCssClass(writer, context);
AddKnockoutDisabledCssDataBind(writer, context, "$gridViewDataSetHelper.dataSet.PagingOptions().IsFirstPage()");
AddKnockoutDisabledCssDataBind(writer, context, "PagingOptions().IsFirstPage()");
GoToPreviousPageButton!.Render(writer, context);

// render template
writer.WriteKnockoutForeachComment("$gridViewDataSetHelper.dataSet.PagingOptions().NearPageIndexes");
writer.WriteKnockoutForeachComment("PagingOptions().NearPageIndexes");

// render page number
NumberButtonsPlaceHolder!.Children.Clear();
Expand All @@ -347,11 +347,11 @@ protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext
writer.WriteKnockoutDataBindEndComment();

AddItemCssClass(writer, context);
AddKnockoutDisabledCssDataBind(writer, context, "$gridViewDataSetHelper.dataSet.PagingOptions().IsLastPage()");
AddKnockoutDisabledCssDataBind(writer, context, "PagingOptions().IsLastPage()");
GoToNextPageButton!.Render(writer, context);

AddItemCssClass(writer, context);
AddKnockoutDisabledCssDataBind(writer, context, "$gridViewDataSetHelper.dataSet.PagingOptions().IsLastPage()");
AddKnockoutDisabledCssDataBind(writer, context, "PagingOptions().IsLastPage()");
GoToLastPageButton!.Render(writer, context);
}

Expand All @@ -368,7 +368,7 @@ protected virtual void RenderPageNumberButton(IHtmlWriter writer, IDotvvmRequest

if (!RenderLinkForCurrentPage)
{
writer.AddKnockoutDataBind("visible", "$data == $parentContext.$gridViewDataSetHelper.dataSet.PagingOptions().PageIndex()");
writer.AddKnockoutDataBind("visible", "$data == $parent.PagingOptions().PageIndex()");
AddItemCssClass(writer, context);
writer.AddAttribute("class", ActiveItemCssClass, true);
var literal = new Literal();
Expand All @@ -379,7 +379,7 @@ protected virtual void RenderPageNumberButton(IHtmlWriter writer, IDotvvmRequest

li.Render(writer, context);

writer.AddKnockoutDataBind("visible", "$data != $parentContext.$gridViewDataSetHelper.dataSet.PagingOptions().PageIndex()");
writer.AddKnockoutDataBind("visible", "$data != $parent.PagingOptions().PageIndex()");
}

li = new HtmlGenericControl("li");
Expand All @@ -390,7 +390,7 @@ protected virtual void RenderPageNumberButton(IHtmlWriter writer, IDotvvmRequest
AddItemCssClass(writer, context);

if (RenderLinkForCurrentPage)
AddKnockoutActiveCssDataBind(writer, context, "$data == $parentContext.$gridViewDataSetHelper.dataSet.PagingOptions().PageIndex()");
AddKnockoutActiveCssDataBind(writer, context, "$data == $parent.PagingOptions().PageIndex()");

li.SetValue(Internal.PathFragmentProperty, "$parent.PagingOptions.NearPageIndexes[$index]");
var link = new LinkButton();
Expand All @@ -404,11 +404,11 @@ protected virtual void RenderPageNumberButton(IHtmlWriter writer, IDotvvmRequest
li.Render(writer, context);
}

// protected override void RenderEndTag(IHtmlWriter writer, IDotvvmRequestContext context)
// {
// base.RenderEndTag(writer, context);
// writer.WriteKnockoutDataBindEndComment();
// }
protected override void RenderEndTag(IHtmlWriter writer, IDotvvmRequestContext context)
{
base.RenderEndTag(writer, context);
writer.WriteKnockoutDataBindEndComment();
}

private IValueBinding GetDataSetBinding()
=> GetValueBinding(DataSetProperty) ?? throw new DotvvmControlException(this, "The DataSet property of the dot:DataPager control must be set!");
Expand Down

0 comments on commit dfa0471

Please sign in to comment.