cancel
Showing results for 
Search instead for 
Did you mean: 

"selectedSortItem" is not set on a ViewSettingsDialog via a JSONModel

Marian_Zeis
Active Contributor
0 Kudos

I try to set the selected Sort Item on a ViewSettingsDialog via an JSONModel.

Unfortunately, the desired ViewSettingsItem is not set under the "sortItems" aggregation.

As a cross check, setting "sortDescending" with JSONModel works.

It also works when I enter the key directly. This example is also described here https://openui5.hana.ondemand.com/entity/sap.m.ViewSettingsDialog/sample/sap.m.sample.ViewSettingsDi...

Here is the ViewSettingsDialog:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
  <ViewSettingsDialog id="linkHeaderViewSettingsDialog" confirm="handleConfirm" sortDescending="{settings>/sortOrderDecending}">
    <sortItems>
      <ViewSettingsItem key="downloadsCurrentFortnight" text="downloadsCurrentFortnight"/>
      <ViewSettingsItem key="downloadsCurrentMonth" text="downloadsCurrentMonth" />
      <ViewSettingsItem id="downloads365" key="downloads365" text="downloads365" selected="{= ${settings>/selectKey} === 'downloads365'}" />
      <ViewSettingsItem key="vscodeInstalls" text="vscodeInstalls"/>
      <ViewSettingsItem key="updatedAt" text="updatedAt" />
      <ViewSettingsItem key="createdAt" text="createdAt" />
      <ViewSettingsItem key="addedToBoUI5" text="addedToBoUI5" />
    </sortItems>
  </ViewSettingsDialog>
</core:FragmentDefinition>

I created a minimum example here: https://github.com/marianfoo/ui5-viewsettingsdialog-sort/tree/main/uimodule/webapp

I deployed this on GitHub Pages here: https://marianfoo.github.io/ui5-viewsettingsdialog-sort/

I also tried to set the "selected" property on "ViewSettingsItem" via JSONModel. That didnt work either.
I can of course set the settings in the controller to the JSONModel, but I would like to avoid that.

Latest OpenUI5 Version 1.103.0 is used here.

Can someone please help me here or nudge me in the right direction.

Accepted Solutions (1)

Accepted Solutions (1)

pmuessig
Advisor
Advisor

Right now there is a timing issue when using databinding which prevents the ViewSettingsDialog being updated with the selected sort item. Therefore a workaround would be to patch the ViewSettingsItem to synchronize the selection in the dialog:

ViewSettingsItem.prototype.setSelected = function(bValue) {
	this.setProperty("selected", bValue, true);
	// synchronize the selected sort item when databinding is used!
	this.getParent() && this.getParent().setSelectedSortItem(this);
	return this;
};

Answers (0)