cancel
Showing results for 
Search instead for 
Did you mean: 

How to fetch multiple records from Odata service into the output table.

0 Kudos

Hi everyone,

As you see in screen shot I have attached in this discussion, I'm trying to fetch data from detail entity set of odata by passing input to it dynamically through master view. In my case the input is BOM number("00000026" as shown in screen shot). I have created a table in my detail.view.xml and trying to do filter & binding in detail.controller.js

when I run follow url in browser it shows expected output in xml format.

http://<host>:<port>/sap/opu/odata/SAP/ZPPBOM_ODATA_SRV/DetailppSet/?$filter= Stlnr eq '00000026'

And when I run project using following code, it neither show any error in consol nor it shows any output in table.

In detail.controller.js there is a variable 'Bomnumber' in which I'm able to get BOM number dynamically from master view.

Please check following xml and js files.

Looking forward for helpful reply.

Regards,

Jagrut Patil.

Detail.view.xml



<Table id="detail1" >

<headerToolbar>

  <Toolbar>

   <Label text="BOM number"></Label>

  </Toolbar>

</headerToolbar>

<columns>

  <Column width="12em">

   <Text text="Item number" />

  </Column>

  <Column minScreenWidth="Tablet" demandPopin="true">

   <Text text="Item Category" />

  </Column>

   <Column minScreenWidth="Tablet" demandPopin="true">

   <Text text="BOM component" />

  </Column>

  <Column minScreenWidth="Tablet" demandPopin="true" hAlign="Right">

   <Text text="Quantity" />

  </Column>

  <Column minScreenWidth="Tablet" demandPopin="true" hAlign="Center">

   <Text text="Unit of measure" />

  </Column>

</columns>

<items>

      <ColumnListItem>

        <cells>

      

          <ObjectIdentifier

            text="{Posnr}" />

        

          <Text text="{Postp}" />

          <Text text="{Idnrk}" />

   <Text text="{Menge}" />

          <Text text="{Meins}" />

      

        </cells>

    

      </ColumnListItem>

    </items>

</Table>

Detail.controller.js


onInit : function() {

var bus = sap.ui.getCore().getEventBus();


bus.subscribe("app", "RefreshDetail", this._refresh, this);


},


_refresh : function(channelId, eventId, data) {

var Bomnumber = data.Bomnumber;

this.getView().byId("bomnumber").getValue(Bomnumber);

var filter = (new sap.ui.model.Filter("Stlnr",

sap.ui.model.FilterOperator.EQ, Bomnumber));

var oModel = new sap.ui.model.odata.ODataModel(

"/sap/opu/odata/SAP/ZPPBOM_ODATA_SRV",

true);


oModel.read("/DetailppSet/?$filter=",filter);

var oTable = new sap.m.Table("detail1");

oTable.setModel(oModel);

},

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

your code is bad.

1) create odata model in onInit

2) bind table in onInit

3) in _refresh do filter on list binding from table

this.byId("detail1").getBinding("items").filter(filter)

0 Kudos

Hello Maksim,

Thanks for the reply. Now I got expected multiple records.

Can you please tell me exactly why we declare model and table in onInit function?

former_member182372
Active Contributor
0 Kudos

Creating Odata model is heavy operation as it involves metadata load and parse. Binding for table needs to be performed just once for majority of cases, so no need to do it in action handler.

0 Kudos

Hi Maksim,

I have another doubt. I'm developing another app, just for practise. The app is for user management.

Means for create, update & delete user. So Page 1 shows total list of user in table. When we click on 'Create' button it navigate to Page 2. In page 2 when we click on 'Save' it saves the data and navigate back to Page 1. So here I'm getting problem, when I click on Save it should refresh Page 1 automatically but in my app I have to reload page manually to see the created data.

I tried   model.refresh();  after mode.create("/Masterset", oEntry, null, Function(success), Function(error)); But its not refreshing data of table in Page 1


So please help me for that.

Regards,

Jagrut.

Former Member
0 Kudos

Hi jagrut,

Instead to navigating to a new page you can give a Dialog Box on click of a create Button.

Try using document.location.reload() method to refresh. This method reloads the page .

regards'

Indrajith

0 Kudos

Hi Indrajith,

Thanks for suggetion, I have used location.reload(); and its working also. But I want to refresh content of table only as it takes some time to reload. So is there any solution for refresh only.

Regards,

Jagrut.

former_member182372
Active Contributor
0 Kudos

well, calling refresh(true) on model should do the thing.

Answers (2)

Answers (2)

kedarT
Active Contributor
0 Kudos

Hi Jagrut,

Hope this helps - JS Bin - Collaborative JavaScript Debugging&lt;/title&gt; &lt;link rel=&quot;alternate&quot; type=&q...

In this example i used JSON model it can be replaced with a oData model.

SergioG_TX
Active Contributor
0 Kudos

HI Jagrut,

try apending the filter as a string such as : $filter=Column eq Value.

i Am not sure if the oModel.read(path, filter) function will work like that, check out in the API what other parameters you can pass to the omodel.read function you would need to pass if you want to go with objects.

hope this helps