Skip to content

Commit

Permalink
Fixed static command paging
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasherceg committed Oct 7, 2023
1 parent dfa0471 commit face71b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Framework/Framework/Controls/DataPager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequest
if (this.LoadData is {} loadData)
{
var loadDataExpression = KnockoutHelper.GenerateClientPostbackLambda("LoadData", loadData, this, new PostbackScriptOptions(elementAccessor: "$element", koContext: CodeParameterAssignment.FromIdentifier("$context")));
helperBinding.Add("loadData", loadDataExpression);
helperBinding.Add("loadDataSet", loadDataExpression);
}
writer.WriteKnockoutDataBindComment("dotvvm-gridviewdataset", helperBinding.ToString());

Expand Down
6 changes: 1 addition & 5 deletions src/Framework/Framework/DotVVM.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@
<ItemGroup>
<!-- the wildcard would not work in Target.Inputs, it only works in Include -->
<TypescriptFile Include="Resources/Scripts/**/*.ts" />
</ItemGroup>

<ItemGroup>
<TypescriptFile Remove="Resources\Scripts\dataset\loader.ts" />
<TypescriptFile Remove="Resources\Scripts\dataset\translations.ts" />
<UpToDateCheckInput Include="Resources/Scripts/**/*.ts" />
</ItemGroup>

<!-- BeforeBuild is ran for every target framework. However, unless its input files change, this target is skipped. -->
Expand Down
32 changes: 19 additions & 13 deletions src/Framework/Framework/Resources/Scripts/dataset/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,36 @@ type GridViewDataSetOptions = {
FilteringOptions: DotvvmObservable<any>
};
type GridViewDataSetResult = {
Items: DotvvmObservable<any[]>,
TotalItemsCount?: DotvvmObservable<number>
Items: any[],
PagingOptions: any,
SortingOptions: any,
FilteringOptions: any
};

export async function loadDataSet(dataSet: GridViewDataSet, loadData: (options: GridViewDataSetOptions) => Promise<GridViewDataSetResult>) {
export async function loadDataSet(dataSetObservable: KnockoutObservable<GridViewDataSet>, loadData: (options: GridViewDataSetOptions) => Promise<DotvvmAfterPostBackEventArgs>) {
const dataSet = ko.unwrap(dataSetObservable);
if (dataSet.IsRefreshRequired) {
dataSet.IsRefreshRequired.setState(true);
}

const result = await loadData({
FilteringOptions: dataSet.FilteringOptions,
SortingOptions: dataSet.SortingOptions,
PagingOptions: dataSet.PagingOptions
FilteringOptions: dataSet.FilteringOptions.state,
SortingOptions: dataSet.SortingOptions.state,
PagingOptions: dataSet.PagingOptions.state
});
const commandResult = result.commandResult as GridViewDataSetResult;

dataSet.Items.setState([]);
dataSet.Items.setState(result.Items.state);
dataSet.Items.setState(commandResult.Items);

const pagingOptions = dataSet.PagingOptions.state;
const totalItemsCount = result.TotalItemsCount?.state;
if (totalItemsCount && ko.isWriteableObservable(pagingOptions.TotalItemsCount)) {
dataSet.PagingOptions.patchState({
TotalItemsCount: result.TotalItemsCount
});
if (commandResult.FilteringOptions && ko.isWriteableObservable(dataSet.FilteringOptions)) {
dataSet.FilteringOptions.setState(commandResult.FilteringOptions);
}
if (commandResult.SortingOptions && ko.isWriteableObservable(dataSet.SortingOptions)) {
dataSet.SortingOptions.setState(commandResult.SortingOptions);
}
if (commandResult.PagingOptions && ko.isWriteableObservable(dataSet.PagingOptions)) {
dataSet.PagingOptions.setState(commandResult.PagingOptions);
}

if (dataSet.IsRefreshRequired) {
Expand Down
4 changes: 2 additions & 2 deletions src/Framework/Framework/Resources/Scripts/dotvvm-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ const dotvvmExports = {
},
translations: translations as any,
dataSet: {
load: loadDataSet,
translations: dataSetTranslations
loadDataSet: loadDataSet,
translations: dataSetTranslations.translations
},
StateManager,
DotvvmEvent,
Expand Down

0 comments on commit face71b

Please sign in to comment.