cancel
Showing results for 
Search instead for 
Did you mean: 

How to bindrows of particular data

soumya_nandi
Participant
0 Kudos

Hi all,

Using NetWeaver Gateway I have bind all the datas present in the backend for demo example flight. But now I want that when I select a flight from that list of flights only for that particular flight the data binding will happen.

But when selecting a particular flight the details of all flights are coming instead of that particular flight.

So that, I want to know that how to bind a specific data in a table.

Regards,

Soumya

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Soumya,

Please find the below code for example of binding data to a table control:

in the view file:

var oTable = new sap.ui.table.Table("table",{

        title: "Materials", 

        rowSelectionChange: oController.rowChange,

        selectionBehavior: sap.ui.table.SelectionBehavior.Row, 

        selectionMode:sap.ui.table.SelectionMode.MultiToggle

        });

  var oColumn = new sap.ui.table.Column({

        label: new sap.ui.commons.Label({text: "Plant"}),

        template: new sap.ui.commons.TextField().bindProperty("value", "werks"),

        sortProperty: "werks",

        filterProperty: "werks"

        });

  oTable.addColumn(oColumn);

        oTable.addColumn(new sap.ui.table.Column("ocolmatnr",{

        label: new sap.ui.commons.Label({text: "Material Number"}),

        template: new sap.ui.commons.Link({press: oController.linkPress}).bindProperty("text", "matnr", function(cellValue){

        if(cellValue)

        {

        cellValue = cellValue.replace(/^0+/, '');

        }

        return(cellValue);

        }),

        sortProperty: "matnr",

        }));

In the controller file:

var oModel = new sap.ui.model.odata.ODataModel("<web-service-url>",

   true, '<username>', '<password>');

  oModel.read("/zget_materialsCollection",null,["$filter=i_search eq '"+search+"' and i_werks eq '"+plant+"'"],true,

  function(data, response)

  {

  var value=[];

  value = data.results;

  console.log(value);

  var oModel1 = new sap.ui.model.json.JSONModel();

  oModel1.setData({ materials: value});

  oModel1.setSizeLimit(300);

  var oTable = sap.ui.getCore().byId("table");

  oTable.setModel(oModel1);

  oTable.bindRows("/materials");

  },

  function()

  {

  jQuery.sap.require("sap.m.MessageToast");

  sap.m.MessageToast.show("No record fetched",{my : "center center",at : "center center"});

  });

Answers (1)

Answers (1)

ChandraMahajan
Active Contributor
0 Kudos

Hi Soumya,

you need to use filter query option to get the data for particular flight and then bind that to table.

you can refer

Regards,

Chandra

soumya_nandi
Participant
0 Kudos

Hi Chandra,

Thanks for your quick and vital response. I have some more query.That are,

By changing the coding in javascript we cannot bind a particular data? We need to change in the odata service itself to filter the data?

Regards,

Soumya

ChandraMahajan
Active Contributor
0 Kudos

you may not even use to code filter query. suppose if you are getting list of flights from OData service as FlightCollection which you will bind to List (or Master or Parent) view. now on click of particular flight, you want to show its details in detailed view. it means you need to read the flightID as key and read from OData service which will be GET_ENTITY operation by passing that particular key.

it will be as FlightCollection('AA') or FlightCollection(flightID='AA')

I will suggest you to go through my blog

you will get clear idea on how to perform query and read operation. also how to use filter operation if you want to read the data based on additional fields.


By changing the coding in javascript we cannot bind a particular data? We need to change in the odata service itself to filter the data?

I will not put code logic to manipulate data in UI if it is possible with model i.e with OData service. you can still do manipulation with javascript coding but it is not best practice as per my opinion.

Regards,

Chandra