Skip to Content
0

sapui5 model read table not updated

Feb 20 at 07:41 AM

26

avatar image
Former Member

Hello,

i am just building my first fiori-app.

The only problem i have, is that the data in the table is not displayed - only the first time.

I searched for this problem, and found many answers - but it still doesn't work.

In my onSearch i do the model.read

So all the data should be in the model. And the model is binded to the table.

Data is returned correct from my get_entityset (logged it to the console)

why is table-data only displayed the first time ?

I tried with .refresh() and some other solutions found in the internet.

I think i have something to code in my success:function...

thanks very much for your help

my controller:

sap.ui.define(["sap/ui/core/mvc/Controller"], function(Controller) {
"use strict";

return Controller.extend("zfi_sako_ausk.controller.View1", {
onInit: function() {
var oDataUrl = "/sap/opu/odata/sap/ZFI_SAKO_AUSK_SRV/";
var ODataModel = new sap.ui.model.odata.v2.ODataModel(oDataUrl);
this.getView().byId("SachkontenTab").setModel(ODataModel);
var oDataUrlBukrs = "/sap/opu/odata/sap/ZFI_BUKRS_SRV/";
var ODataModelBukrs = new sap.ui.model.odata.v2.ODataModel(oDataUrlBukrs);
this.getView().byId("cbBukrs").setModel(ODataModelBukrs);
},

onSearch: function() {
var oModel = this.getView().byId("SachkontenTab").getModel();
var bukrs = this.getView().byId("cbBukrs").getSelectedKey();
var suchbegriff = this.getView().byId("searchField").getValue();
var allFilters = [];
allFilters.push(new sap.ui.model.Filter("Bukrs", sap.ui.model.FilterOperator.EQ, bukrs));
allFilters.push(new sap.ui.model.Filter("Txt50Skat", sap.ui.model.FilterOperator.EQ, suchbegriff));
oModel.read("/SachkontenSet", {
filters: allFilters,
success: function() {

},
error: function() {
sap.m.MessageToast.show("Fehler bei read Sachkontenset");
}
});

}

});
});

Part of my View:

<Table id="SachkontenTab" items="{/SachkontenSet}" enableCellFilter="true">
<columns>
<Column filterProperty="Buchungskreis">
<Text text="Buchungskreis"/>
</Column>
<Column>
<Text text="Sachkonto"/>
</Column>
<Column width="20%">
<Text text="Langtext"/>
</Column>
<Column width="20%">
<Text text="Schlagworte"/>
</Column>
<Column width="40%">
<Text text="KontierungsInfo"/>
</Column>
<Column>
<Text text="Kontenplan"/>
</Column>
</columns>
<items>
<ColumnListItem type="Active">
<cells>
<Text text="{Bukrs}"/>
<Text text="{Saknr}"/>
<Text text="{Txt50Skat}"/>
<Text text="{Schlw}"/>
<Text text="{Konti}"/>
<Text text="{Ktopl}"/>
</cells>
</ColumnListItem>
</items>
</Table>

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Vaibhav Maheshwari Feb 21 at 04:33 AM
0

Instead of explicitly calling the read method, you can just refresh the model binding by passing the filter criteria as filters.

Try the following in your search method :

var oTable = this.getView().byId("SachkontenTab");

var oBinding = oTable.getBinding("items");

var bukrs = this.getView().byId("cbBukrs").getSelectedKey();
var suchbegriff = this.getView().byId("searchField").getValue();
var allFilters = [];
allFilters.push(new sap.ui.model.Filter("Bukrs", sap.ui.model.FilterOperator.EQ, bukrs));
allFilters.push(new sap.ui.model.Filter("Txt50Skat", sap.ui.model.FilterOperator.EQ, suchbegriff));

oBinding.filter(new sap.ui.model.Filter(allFilters, true));

Share
10 |10000 characters needed characters left characters exceeded