cancel
Showing results for 
Search instead for 
Did you mean: 

Table binding using OData......

former_member213574
Participant
0 Kudos

Hi All,

I am having two set of odata response which I am retrieving through oModel.Read.

testarray[0] = oData;

testarray[1] = oData;

After this the the generated array of objects is converting to an object like this

var rg = {};

for (var i = 0; i < testarray.length; ++i)

     {

  rg[i] = testarray[i];

   }

Setting a model:

var singleRowModel = new sap.ui.model.json.JSONModel({});

var oTable = new sap.ui.table.Table("oTable");

  oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "Rate Category"}),template: new sap.ui.commons.TextView({text: "{RateCategory}"})}));

  oTable.addColumn(new sap.ui.table.Column({label: new sap.ui.commons.Label({text: "Net Amount"}),template: new sap.ui.commons.TextView({text: "{NetAmount}"})}));

oTable.setModel(singleRowModel, "singleRowModel");

singleRowModel.setData(rg);

oTable.bindRows("singleRowModel");

Now i can see in the console the defined oTable is loaded with the singleRowModel with odata as two Objects which i got from the odata response earlier.

singleRowModel

F {mEventRegistry: Object, oData: Object, bDestroyed: false, aBindings: Array[0],mContexts: Object…}

  1. aBindings: Array[0]
  2. aPendingRequestHandles: Array[0]
  3. bCache: true
  4. bDestroyed: false
  5. bLegacySyntax: false
  6. iSizeLimit: 100
  7. mContexts: Object
  8. mEventRegistry: Object
  9. mSupportedBindingModes: Object
  10. oData: Object
    1. 0: Object
      1. DifferenceAmount: "0.00"
      2. GrossAmount: "618.03"
      3. NetAmount: "525.98"
      4. RateCategory: "GT_MWS"
      5. RateCategoryTxt: "Global temp metered and sewerage"
      6. Ratecat: "GT_MWS"
      7. SelRatecat: ""
      8. Simfrom: "2015-03-18T00:00:00"
      9. Simto: "2016-03-17T00:00:00"
      10. TaxAmount: "92.05"
      11. Vertrag: "50000267"
      12. Wears: "GBP"
      13. __metadata: Object
      14. __proto__: Object
    2. 1: Object
      1. DifferenceAmount: "70.68"
      2. GrossAmount: "688.71"
      3. NetAmount: "586.14"
      4. RateCategory: "NEWMET"
      5. RateCategoryTxt: "New metered"
      6. Ratecat: "GT_MWS"
      7. SelRatecat: "NEWMET"
      8. Simfrom: "2015-03-18T00:00:00"
      9. Simto: "2016-03-17T00:00:00"
      10. TaxAmount: "102.57"
      11. Vertrag: "50000267"
      12. Wears: "GBP"
      13. __metadata: Object
      14. __proto__: Object
    3. __proto__: Object
  11. sDefaultBindingMode: "TwoWay"
  12. __proto__: F

oTable

F {bAllowTextSelection: true, mEventRegistry: Object, sId: "oTable", mProperties: F, mAggregations: Object…}

  1. _aIdxCols2Cells: Array[2]
  2. _aVisibleColumns: Array[2]
  3. _bAccMode: true
  4. _bActionMode: false
  5. _bAllowColumnHeaderTextSelection: false
  6. _bCallUpdateTableCell: false
  7. _bForceVisibleColCalc: false
  8. _bInheritEditableToControls: false
  9. _bOnAfterRendering: false
  10. _bRtlMode: false
  11. _bSyncScrollLeft: false
  12. _bjQueryLess18: false
  13. _clicksRegistered: 0
  14. _doubleclickDelay: 300
  15. _iColMinWidth: 20
  16. _iLastFixedColIndex: -1
  17. _iOldScrollLeft: 0
  18. _iOldScrollRight: 0
  19. _iTimerDelay: 250
  20. _lastParent: div#__dialog0-scrollCont.sapMDialogScrollCont
  21. _lastParentHeight: 0
  22. _lastParentWidth: 0
  23. _oCalcColumnWidths: Array[0]
  24. _oColHdrItemNav: E.extend.constructor
  25. _oHSb: f
  26. _oItemNavigation: E.extend.constructor
  27. _oResBundle: B
  28. _oSelection: E.extend.constructor
  29. _oVSb: f
  30. _sBindingTimer: undefined
  31. _sColHdrPosTimer: 218
  32. _sOwnerId: undefined
  33. _sScrollBarTimer: 178
  34. aBeforeDelegates: Array[0]
  35. aDelegates: Array[2]
  36. bAllowTextSelection: true
  37. bOutput: true
  38. iSuppressInvalidate: 0
  39. mAggregations: Object
  40. mAssociations: Object
  41. mBindingInfos: Object
  42. mBindingParameters: null
  43. mBoundObjects: Object
  44. mEventRegistry: Object
  45. mMethods: Object
  46. mProperties: F
  47. oBindingContexts: Object
  48. oModels: Object
    1. singleRowModel: F
      1. aBindings: Array[0]
      2. aPendingRequestHandles: Array[0]
      3. bCache: true
      4. bDestroyed: false
      5. bLegacySyntax: false
      6. iSizeLimit: 100
      7. mContexts: Object
      8. mEventRegistry: Object
      9. mSupportedBindingModes: Object
      10. oData: Object
        1. 0: Object
          1. DifferenceAmount: "0.00"
          2. GrossAmount: "618.03"
          3. NetAmount: "525.98"
          4. RateCategory: "GT_MWS"
          5. RateCategoryTxt: "Global temp metered and sewerage"
          6. Ratecat: "GT_MWS"
          7. SelRatecat: ""
          8. Simfrom: "2015-03-18T00:00:00"
          9. Simto: "2016-03-17T00:00:00"
          10. TaxAmount: "92.05"
          11. Vertrag: "50000267"
          12. Wears: "GBP"
          13. __metadata: Object
          14. __proto__: Object
        2. 1: Object
          1. DifferenceAmount: "70.68"
          2. GrossAmount: "688.71"
          3. NetAmount: "586.14"
          4. RateCategory: "NEWMET"
          5. RateCategoryTxt: "New metered"
          6. Ratecat: "GT_MWS"
          7. SelRatecat: "NEWMET"
          8. Simfrom: "2015-03-18T00:00:00"
          9. Simto: "2016-03-17T00:00:00"
          10. TaxAmount: "102.57"
          11. Vertrag: "50000267"
          12. Wears: "GBP"
          13. __metadata: Object
          14. __proto__: Object
        3. __proto__: Object
      11. sDefaultBindingMode: "TwoWay"
      12. __proto__: F
    2. __proto__: Object
  49. oParent: F
  50. oPropagatedProperties: Object
  51. sBindingPath: null
  52. sId: "oTable"
  53. sParentAggregationName: "content"
  54. __proto__: F

But while displaying I am not getting empty table, Can anyone please help where is the issue?

Regards,

Arun

Accepted Solutions (1)

Accepted Solutions (1)

kai2015
Contributor
0 Kudos

Try that

var oTable = new sap.ui.table.Table("oTable");

  oTable.addColumn(new sap.ui.table.Column({

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

template: new sap.ui.commons.TextView({text: "{singleRowModel>RateCategory}"})}));

  oTable.addColumn(new sap.ui.table.Column({

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

template: new sap.ui.commons.TextView({text: "{singleRowModel>NetAmount}"})}));

oTable.bindRows("singleRowModel>/");

former_member213574
Participant
0 Kudos

Hi Kai Helferich,

I tried that but still the table is showing no Data....But i could see from the console the Omodel is added in the Table as in the screenshot which i shared with my question.

singleRowModel: F , I have a doubt normally it will be some constructor, but here inside table it is coming as  F

Regards,

Arun

kai2015
Contributor
0 Kudos

Hi Arun,

see working sample here: JS Bin

Second mistake you have done:

var rg = {};  //Value / Key Array

=>

var rg = []; //Simple Array


What's the difference?

Read this: JavaScript Arrays: The Difference Between [] and { }


kind regards

Kai

former_member213574
Participant
0 Kudos

Hi Kai Helferich,


Thanks for the example.


Finally I got the solution...


The error was in setting up the model for the table,


I approached as below:


singleRowModel.setData({items:testarray});

  oTable.setModel(singleRowModel, "singleRowModel");

// oTable.bindRows("singleRowModel>/items");

  oTable.bindItems("singleRowModel>/items", oRow);

Now it is working perfectly fine.

Regards,

Arun

Answers (0)