diff --git a/src/Framework/Framework/Controls/DataPager.cs b/src/Framework/Framework/Controls/DataPager.cs index 0165df034b..7292dcd86b 100644 --- a/src/Framework/Framework/Controls/DataPager.cs +++ b/src/Framework/Framework/Controls/DataPager.cs @@ -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()); diff --git a/src/Framework/Framework/DotVVM.Framework.csproj b/src/Framework/Framework/DotVVM.Framework.csproj index f5853aca59..ad0abe8fd7 100644 --- a/src/Framework/Framework/DotVVM.Framework.csproj +++ b/src/Framework/Framework/DotVVM.Framework.csproj @@ -123,11 +123,7 @@ - - - - - + diff --git a/src/Framework/Framework/Resources/Scripts/dataset/loader.ts b/src/Framework/Framework/Resources/Scripts/dataset/loader.ts index fbeb7122ac..78f8d3121f 100644 --- a/src/Framework/Framework/Resources/Scripts/dataset/loader.ts +++ b/src/Framework/Framework/Resources/Scripts/dataset/loader.ts @@ -11,30 +11,36 @@ type GridViewDataSetOptions = { FilteringOptions: DotvvmObservable }; type GridViewDataSetResult = { - Items: DotvvmObservable, - TotalItemsCount?: DotvvmObservable + Items: any[], + PagingOptions: any, + SortingOptions: any, + FilteringOptions: any }; -export async function loadDataSet(dataSet: GridViewDataSet, loadData: (options: GridViewDataSetOptions) => Promise) { +export async function loadDataSet(dataSetObservable: KnockoutObservable, loadData: (options: GridViewDataSetOptions) => Promise) { + 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) { diff --git a/src/Framework/Framework/Resources/Scripts/dotvvm-root.ts b/src/Framework/Framework/Resources/Scripts/dotvvm-root.ts index 47fb4e91bd..223c4a7aac 100644 --- a/src/Framework/Framework/Resources/Scripts/dotvvm-root.ts +++ b/src/Framework/Framework/Resources/Scripts/dotvvm-root.ts @@ -125,8 +125,8 @@ const dotvvmExports = { }, translations: translations as any, dataSet: { - load: loadDataSet, - translations: dataSetTranslations + loadDataSet: loadDataSet, + translations: dataSetTranslations.translations }, StateManager, DotvvmEvent,