cancel
Showing results for 
Search instead for 
Did you mean: 

ODATAModel Table binding delay problem

venkatachala_ck
Active Participant
0 Kudos

Hi,

I'm using sap.m.Table inside dialog box and binding ODATAModel .

my problem is i'm counting number rows in table (using oTable.getItems().length) and displaying as dialog box titile( ex: Lines(10))

due to more number of records binding is taking time

and count is displaying as "0" .

my code :

onClickPriority: function() {

  var oTablePriority = new sap.m.Table(

  {

  inset: true,

  headerDesign: sap.m.ListHeaderDesign.Standard,

  mode: sap.m.ListMode.None,

  });

  var col = new sap.m.Column(

  {

  });

  oTablePriority.addColumn(col);

  var col1 = new sap.m.Column(

  {

  header: new sap.m.Label({

  text: "Priority"

  })

  });

  oTablePriority.addColumn(col1);

  var col2 = new sap.m.Column(

  {

  header: new sap.m.Label({

  text: "Priority Text"

  })

  });

  oTablePriority.addColumn(col2);

  var dialogTablePriority = new sap.m.Dialog({

    

  content: [oTablePriority],

  beforeOpen: function(){

     var oModelPriority = new sap.ui.model.odata.ODataModel("http://xxxxxxxxxxxxxxxxxx_SRV/");

  oTablePriority.setModel(oModelPriority);

      

  oTablePriority.bindItems("/NotificationPriorityCollection",

  new sap.m.ColumnListItem({

  cells: [new sap.m.RadioButton({

  select: function(evt) {

  var pathno = evt.getSource().getBindingContext().getPath();

  var in1 = pathno.split("/");

  index = in1[1]; // Index

  }

  }),

  new sap.m.Text({

  text: "{Priority}"

  }),

  new sap.m.Text({

  text: "{PriorityText}"

  })]

  }));

  },

  afterOpen : function(){

   dialogTablePriority.setTitle("Priority("+oTablePriority.getItems().length + ")");

  },

  beginButton: new sap.m.Button({

  text: 'Select',

  press: function() {

  var Priority = oTablePriority.getModel().oData[index].Priority;

  var PriorityText = oTablePriority.getModel().oData[index].PriorityText;

  oView.byId('Priorityid').setValue(Priority);

  oView.byId('PriorityTextid').setValue(PriorityText);

  dialogTablePriority.close();

  }

  }),

 

  endButton: new sap.m.Button({

  text: 'Cancel',

  press: function() {

  dialogTablePriority.close();

  }

  }),

  beforeClose: function(){

       var allItems = oTablePriority.getItems();

  var len = allItems.length;

  console.log(len); 

  }

  });

       

  dialogTablePriority.open();

  },

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

oTablePriority.bindItems("/NotificationPriorityCollection",

........

var binding = oTablePriority.getBinding("items");

if(binding)

{

  binding.attachDataReceived(function () {

  dialogTablePriority.setTitle("Priority("+oTablePriority.getItems().length + ")");

  }, this);

}

venkatachala_ck
Active Participant
0 Kudos

Hi Maksim Rashchynski,

thank you for the response.

Sorry for the late reply i was busy in other project and now i used your code its working

Answers (1)

Answers (1)

saivellanki
Active Contributor
0 Kudos

Hi Venkatachala,

Rather than fetching the length using oTable.getItems(), why don't you achieve the same using model.

Try -


dialogTablePriority.setTitle(sap.ui.getCore().getModel().getProperty("/NotificationPriorityCollection").length);

Regards,

Sai Vellanki.

venkatachala_ck
Active Participant
0 Kudos
SergioG_TX
Active Contributor
0 Kudos

it seems like your dialogTablePriority object is not initialized on your afterOpen event. please make sure you get a handle of the dialog before you can use that object.

once you have a handle of the correct object, then you can access its properties. it will be something like 

var dialog = sap.ui.getCore().byId(idOfYourDialogObject);

then you can use your one line inside your afterOpen event.

I suggest to add a breakpoint and see if you got the correct object

venkatachala_ck
Active Participant
0 Kudos

Same error

i used this code

sap.ui.getCore().byId("dialogTablePriority_id").setTitle(sap.ui.getCore().getModel().getProperty("/NotificationPriorityCollection").length);

SergioG_TX
Active Contributor
0 Kudos

does the service run? based on the error it doesn't seem like it gets any data

try querying the service from the browser  or post man first to see if anything is coming back from the service

venkatachala_ck
Active Participant
0 Kudos

I'm getting Data and it is displaying in dialog box also

only Title problem

SergioG_TX
Active Contributor
0 Kudos

can you try:

var dialog = this.byId(idOfYourDialogObject);

and see if you get a handle of the object first

former_member182372
Active Contributor
0 Kudos

When you try to open that URl in browser- do you see any data?