Skip to Content
avatar image
Former Member

Dailog not showing Binded values on first click

Hi Team ,

I have a scenario were in on a button click , a pop up dailog needs to be displayed. the Pop up dailog contains table with values fetched from Odata service call.

The issue is the pop up dailog doesnot show the binded data on first click, however if the pop up os triggered while clicking on button fofr the second time the dailog shows the binded values.

Approach followed :

1. on the Button press function -> Dailog code is written

_onButtonPress3: function(oEvent) {
				var dialogName = "D3_1487657716618";
				this.dialogs = this.dialogs || {};
				var dialog = this.dialogs[dialogName];
					var source = oEvent.getSource();
					var bindingContext = source.getBindingContext();
					var path = bindingContext ? bindingContext.getPath() : null;
					var model = bindingContext ? bindingContext.getModel() : this.getView().getModel();
				var view;
				if (!dialog) {
					view = sap.ui.xmlview({
						viewName: "ml001.app.view." + dialogName
					});
					view._sOwnerId = this.getView()._sOwnerId;
					//need to set router so we can use navigation in dialogs
					view.getController().setRouter(this.oRouter);
					dialog = view.getContent()[0];
					this.dialogs[dialogName] = dialog;
				}
				return new ES6Promise.Promise(function(resolve, reject) {
						dialog.attachEventOnce("afterOpen", null, resolve);
						dialog.open();
						if (view) {
							dialog.attachAfterOpen(function() {
								dialog.rerender();
							});
						} else {
							view = dialog.getParent();
						}
						view.setModel(model);
						if (path) {
							view.bindElement(path, {});
						}
					}); 


2. On dailog initialise which triggers dailog .js file init function in this service call is made.

		onAfterRendering: function() {
			var bindingParameters;


			var filterData;
		},


		onInit: function() {
			////////////////////////////////////////
			//	Dialogue initialisation with Odata Service
			///////////////////////////////////////			
			//	Begin of code by Sakshi Sawhney on 8/3/2017 
			//	Creating model for odata service -> Done only once per lifecycle of view
			var oModTiles = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZML001_NOTIF_SERVORD_SRV/", true);
			// setting model to the current view
			var curr_view = this.getView("D3_1487657716618");
			///////////////////////////
			//creating a template of row of the table
			var otemplate1 = curr_view.byId("activitysuggrow");
			// binding the rows of table with the model data we created above


			//Setting up filter of notification number
			var oFilters = [new sap.ui.model.Filter("notif_number", "EQ", "300000010")];
			debugger;
			curr_view.byId("activitysugg").bindAggregation("items", "/activ_suggSet", otemplate1, null, oFilters);
			curr_view.setModel(oModTiles);
			this._oDialog = this.getView().getContent()[0];
		},
		onExit: function() {
			this._oDialog.destroy();
		},
		setRouter: function(oRouter) {
			this.oRouter = oRouter;
		},
		_onButtonPress: function() {
			var oDialog = this.getView().getContent()[0];


			return new ES6Promise.Promise(function(resolve, reject) {
				oDialog.attachEventOnce("afterClose", null, resolve);
				oDialog.close();
			});


		},

Would be grateful if inputs could be provided in this regard.Placing dailog initializaion in view controller init function does not give issue but i want to avoid unnecessary call to service during view load.

Also this code is majorily imported from BUILD, binding related code is written in above snippet.

ON first click on button

ON second click

first.png (30.0 kB)
second.png (47.1 kB)
second.png (47.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Mar 09, 2017 at 08:00 PM

    i guess problem is not with binding...check if you see any backend call on first launch of dialog

    Possible reason could be on first time launch backend call is triggered but data is not received back making you think that no data in the screen, on second click data which is already retrieved as part of opening dailog for the first time is shown...

    check the network tab for backend call on first time launch..

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 09, 2017 at 08:12 PM

    it took a while to load the data..probably

    Add comment
    10|10000 characters needed characters exceeded