Binding oData read data into sap.m.Table

5.6k Views Asked by At

I'm trying to show some data fetched using oDataModel.read. I'm able to get the data using my filter values as I can see in the network tab. But when I try to show that data into the table, I"m not able to. I've seen various discussions on SCN but doesn't seem to work.

I"m able to get the data with bindAgreggation & show it in the table as well but there the problem is my filters aren't working properly.

Please have a look at the below code that I"m using to do the above & suggest how can I show the data in the table.

oDataModel.read Approach Reading Data:

this.oDataModel.read("/AllocationDocSet", null, ["$filter=Budat ge '" + wkStart + "' and Budat le '" + wkEnd + "'"], true, function(retObj){
      retFunc(retObj.results);
    },
Setting data into table:

this.oService.getDocsList(this, calModel.getData().weekStart, calModel.getData().weekEnd, function(retData){
        console.log('setting table model');
        var docsTable = thisRef.byId('ENTRY_LIST_CONTENTS');
        var oTemplate = new sap.m.ColumnListItem(
          {cells: [
                  new sap.m.Text({text : "{Skostl}"}),
                  new sap.m.Text({text : "{Slstar}"}),
                  new sap.m.Text({text : "{Ktext}"}),
                  new sap.m.Text({text : "{Eaufnr}"}),
                  new sap.m.Text({text : "{Epspnr}"}),
                  new sap.m.Text({text : "{Mbgbtr}"}),
                  new sap.m.Text({text : "{Meinh}"}),
                  ]
          });

        var docsModel = new sap.ui.model.json.JSONModel();
        console.log('length: '+retData.length);
        docsModel.setData(retData);
        docsTable.setModel(docsModel);
        docsTable.bindAggregation('items',{path: '/retData',template: oTemplates});

Bind agreggation approach:

var wkStartFilter = new sap.ui.model.Filter("Budat", sap.ui.model.FilterOperator.GE, calModel.getData().weekStart);
    var wkEndFilter = new sap.ui.model.Filter("Budat", sap.ui.model.FilterOperator.LE, calModel.getData().weekEnd);
    var buFilters = [];
    buFilters.push(wkStartFilter);
    buFilters.push(wkEndFilter);
    var oTemplate = new sap.m.ColumnListItem(
          {cells: [
                  new sap.m.Text({text : "{Skostl}"}),
                  new sap.m.Text({text : "{Slstar}"}),
                  new sap.m.Text({text : "{Ktext}"}),
                  new sap.m.Text({text : "{Eaufnr}"}),
                  new sap.m.Text({text : "{Epspnr}"}),
                  new sap.m.Text({text : "{Mbgbtr}"}),
                  new sap.m.Text({text : "{Meinh}"}),
                  ]
          });
    var docsTable = thisRef.byId('ENTRY_LIST_CONTENTS');
    docsTable.bindAggregation('items', {path: '/AllocationDocSet',template: oTemplate, filters: buFilters});

Prompt responses will be much appreciated.

Thanks, AW

1

There are 1 best solutions below

0
On

Specify the columns needed for table

var docsTable = new sap.m.Table("idtableorders", {
        growing : true,
        growingThreshold : 10,
        columns : [ 
            new sap.m.Column({}), 
            new sap.m.Column({}), 
            new sap.m.Column({}), 
            new sap.m.Column({}), 
            new sap.m.Column({}),
            new sap.m.Column({}), 
            new sap.m.Column({}) 
            ]
    });