Skip to Content
0

SAPUI5: Refreshing data in a Table.

Sep 12, 2017 at 11:38 AM

79

avatar image
Former Member

Hi Experts,

I need a button thats refreshes the data in a Ui5-Table from the backend (SAP Gateway), currently for testing im pressing my back button and than my go to this Page button.

How can I implement the same Result as one single button?

I tried oODataModel.refresh(true); But it does not work.

My Code is below.

Regard Jan

	onInit: function(){
		//Define the Service URL 
		var sServiceURL = "/sap/opu/odata/SAP/ZPCC_PT_MONITOR_SRV/";
		//Create the instance of the OData Model
		var oODataModel = new sap.ui.model.odata.v2.ODataModel(sServiceURL, {
			json : true,
			tokenHandling : true,
			refreshAfterChange: true,
			useBatch : true,
			defaultBindingMode : sap.ui.model.BindingMode.TwoWay,
			defaultCountMode : "Inline"
		});
		
		//Set the Model on the View
		this.getView().setModel(oODataModel);
		this.getView().addEventDelegate({
			onBeforeShow : function(oControlEvent){	
				var oGlobalJSONModel = sap.ui.getCore().getModel("globalModel");
				//Get the Table through its id
				var oTableNodeEvents = sap.ui.getCore().byId("TableNodeEvents");
				sap.ui.getCore().byId("tableTitle").setText(oGlobalJSONModel.getProperty("/Pname")); //Hier kommt der titel her
				//Set the Node name as Header Parameter
				oODataModel.setHeaders({
					"Pname" : oGlobalJSONModel.getProperty("/Pname")
				});
				oODataModel.read("/NodeEventsDataSet",{
					success : function(oData, response){
						var oJSONModelForNodeEventsDataSet = new sap.ui.model.json.JSONModel(oData.results);
						oTableNodeEvents.setModel(oJSONModelForNodeEventsDataSet);
						oTableNodeEvents.bindRows("/");
					},
					error : function(oError){
						//TODO HTTP Request failed, Display Error Message
					}
				});
			}
		});
	},
	
	handleButtonBackPress : function(oControlEvent){
		var oController = this;
		
		oController.nav.to("StartPage");
		
	},
	
	handleRefreshButtonPress : function(oControlEvent){
		var oController = this;
		var oODataModel = oController.getView().getModel();


		oODataModel.refresh(true);
		
		var oMessageStrip = sap.ui.getCore().byId("messageStrip");		
		oMessageStrip.setType(sap.ui.core.MessageType.Information);
		oMessageStrip.setText("{i18n>MessageStripRefresh}")
		oMessageStrip.setVisible(true);
		
	},
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
avatar image
Former Member Sep 12, 2017 at 02:37 PM
0

Hi,

If you have used sap.ui.table.Table then try this:

oTable.getBinding("rows").refresh();

else if you have used sap.m.Table then try this:

oTable.getBinding("items").refresh();

Regards,

Rahul

Share
10 |10000 characters needed characters left characters exceeded