Under v1.71, my code is working randomly (litteraly, sometimes the table displays the items correctly sometimes it doesn't) although it is perfectly working under v1.6+.
I'm working under 1.17.21
My default model is two-way binded.
The table is created in the xml view :
<Table id="tableId" items="{Items}" delete=".onDeleteRow" mode="Delete" noDataText="{i18n>noItems}">
<headerToolbar>
<OverflowToolbar>
<Title text="{i18n>addedItems}" level="H3"/>
<ToolbarSpacer></ToolbarSpacer>
<Button icon="sap-icon://add" press=".onAddItemPress" tooltip="{i18n>addButtonTooltip}"/>
</OverflowToolbar>
</headerToolbar>
<columns>
<Column hAlign="Center" minScreenWidth="Small" demandPopin="true" popinDisplay="Inline">
<header>
<Label text="{/#PRItem/ShortText/@sap:label}"/>
</header>
</Column>
<Column hAlign="Center" minScreenWidth="Small" demandPopin="true" popinDisplay="Inline">
<header>
<Label text="{/#PRItem/Quantity/@sap:label}"/>
</header>
</Column>
<Column hAlign="Center" minScreenWidth="Small" demandPopin="true" popinDisplay="Inline">
<header>
<Label text="{/#PRItem/PriceUnit/@sap:label}"/>
</header>
</Column>
<Column hAlign="Center" minScreenWidth="Small" demandPopin="true" popinDisplay="Inline">
<header>
<Label text="{/#PRItem/Price/@sap:label}"/>
</header>
</Column>
<Column id="editIconColumn" hAlign="End" width="50px"/>
</columns>
<items>
<ColumnListItem>
<cells>
<Text text="{ShortText}"/>
<Text text="{Quantity}"/>
<Text text="{Quantity}"/>
<Text text="{parts [path:'Price', path:'Quantity', path:'PriceUnit'], formatter: this.formatter.setSousTotal}"/>
<core:Icon src="sap-icon://edit-outside" press=".onEditIconPress" tooltip="{i18n>editIconTooltip}"/>
</cells>
</ColumnListItem>
</items>
</Table>
And I bind the view context and items as follows:
_createPurchaseRequest: function () {
var oContext = this.getOwnerComponent().getModel().createEntry("/PRHeaderSet");
this.getView().setBindingContext(oContext);
this._getDefaultValues();
},
onAddItemPress: function (oEvent) {
var oView = this.getView(),
// oModel = this.getOwnerComponent().getModel(),
oModel = this.getModel(),
oHdrCtx = oView.getElementBinding() ? oView.getElementBinding().getBoundContext() : oView.getBindingContext(),
oItemContext = oModel.createEntry("/PRItemSet"),
aAllItems = this._getArrayOrDefault(oModel.getProperty(oHdrCtx.getPath() + "/Items"));
aAllItems.push(oItemContext.getPath().substring(1));
oModel.setProperty("Items", aAllItems, oHdrCtx);
this.getOwnerComponent().getModel("createViewModel").setProperty("/mode", "creationMode");
oModel.setProperty("Quantity", "7", oItemContext);
},
_getArrayOrDefault: function (e) {
return e ? Array.from(e) : [];
},
The aggregation("items") is correctly binded but sometimes its properties aKeys and aAllKeys are empty so the table doesn't display anything.
Not working (after trying to add an item or more)
A comparison between a working case (left) and a non working one (right) :
Can anyone see the isse?
Well I don't really understand but I managed to resolve my problem by giving more time to the framework to make two independents operations which are setting the context to the view and get the defaults values. I mean independents here because I don't need those default values to set the context et I could get those values without setting the former.