Skip to Content

SAPUI5 - SmartTable does not update when binding changes

Dec 04, 2016 at 12:05 PM


avatar image


I am quite new to SAPUI5 and I am supposed to develop an application that consumes a OData service and show the data in a table. Furthermore, I also need to be able to make updates to the OData.

I have no prior knowledge to SAPUI5 - I basically just got asked to use SAPUI5 and then I was on my own. So I have tried to do some tutorials at and just follow a "trial and error" approach.

Now, I am able to retrieve data from the OData service (a service my organisation has given me) and show it in a SmartTable in a second view. The user chooses the entityset and so on he wants to have displayed and then the view changes to the smarttable. This works the first time you try. However, if you navigate back to the previous view to change the setting and try again, the table doesnt refresh. I feel like I have tried everything, and I just cant seem to make it work. If I get this to work, I feel like I will also be able to implement a much better way to update the odata, than what you can see in my code.

The first view:


The code for this view:

], function(BaseController, MessageToast) {
	"use strict";

	return BaseController.extend("DemoApplication.controller.Home", {

		onInit: function() {

			//Get fields
			this.apiURLComboBox = this.getView().byId("selectedAPI");
			this.instanceInputField = this.getView().byId("selectedInstance");
			this.usernameInputField = this.getView().byId("selectedUsername");
			this.passwordInputField = this.getView().byId("selectedPassword");
			this.tableComboBox = this.getView().byId("selectedTable");
			this.selectedParameters = this.getView().byId("selectedParameters");
			this.requestTableButton = this.getView().byId("requestTableButton");

			//Initiate variables
			this.JSONModel = new sap.ui.model.json.JSONModel();
			this.JSON = {};

		//Eventhandler when the Refresh button is pushed
		refreshTables: function(oEvent) {

			//Destroy items inside Table ComboBox

			try {

				//Retrieve oDATA with the selected API URL and entered instance, username and password
				this.oDataModel = new sap.ui.model.odata.ODataModel(this.apiURLComboBox.getSelectedKey(), true, this.usernameInputField.getValue() +
					"@" + this.instanceInputField.getValue(),
				//Get EntitySets 
				this.entitySets = this.oDataModel.getMetaModel().getODataEntityContainer(false).entitySet;

				//For loop that adds the entity names into the Table ComboBox
				for (var i = 0; i < this.entitySets.length; i++) {

					this.tableComboBox.addItem(new sap.ui.core.Item({
						text: this.entitySets[i].name,
						key: this.entitySets[i].name


			} catch (err) {"Could not retrieve tables.\nPlease check your login informations.");

		//Eventhandler when a table is choosed
		tableChoosed: function(oEvent) {

			//Empty the selected parameters, if any where selected

			//Set Button text
			this.requestTableButton.setText("Request " + this.tableComboBox.getSelectedKey());

			//Get the selected table key
			var sEntity = this.tableComboBox.getSelectedKey();

			//Go enter the oDATA and get the properties of the selected entity
			this.entityProperties = this.oDataModel.oMetadata._getEntityTypeByPath(sEntity).property;

// + "(" + this.oDataModel.oMetadata._getEntityTypeByPath(sEntity).key +  ")", {success: this.suc, error: this.err});

			//Instantiate visible fields with an array containing the length of the amount 
			//of properties(columns) the entity has.
			this.visibleEntityFields = Array(this.entityProperties.length);

			//Instantiate empty array for invisible fields
			this.invisibleEntityFields = Array();

			//Check whether the column is visible or not.
			for (var i = 0; i < this.entityProperties.length; i++) {
				//If visible, add it as a visible field and create an item into the Parameters MultiBox
				if (this.entityProperties[i].extensions[4].value === "true") {
					this.visibleEntityFields[i] = this.entityProperties[i].name;

					this.selectedParameters.addItem(new sap.ui.core.Item({
						text: this.entityProperties[i].name,
						key: this.entityProperties[i].name

				//If not visible, add it to the invisible array
				} else {


/*		suc : function(data){
			alert("hej" + data);
		err : function(data){


		//Get router function
		getRouter: function() {
			return sap.ui.core.UIComponent.getRouterFor(this);

		//Display not found function
		onDisplayNotFound: function(oEvent) {
			//Display the notFound target without changing the hash
			this.getRouter().getTargets().display("notFound", {
				fromTarget: "home"

		//Navigate to third page --> not used atm.
		onNavToPerPersonal: function(oEvent) {

		//Navigate to the table view
		onNavToTableView: function(oEvent) {

			//Fill the JSON variable with the values selected
			this.JSON.apiURL = this.apiURLComboBox.getSelectedKey();
			this.JSON.instance = this.instanceInputField.getValue();
			this.JSON.username = this.usernameInputField.getValue();
			this.JSON.password = this.passwordInputField.getValue();
			this.JSON.table = this.tableComboBox.getSelectedKey();
			this.JSON.chosenEntityFields = this.selectedParameters.getSelectedKeys();
			this.JSON.visibleEntityFields = this.visibleEntityFields;
			this.JSON.invisibleEntityFields = this.invisibleEntityFields;

			//Add the JSON to the JSONModel and refresh

			//Set the oDATA model to the core and refresh
			sap.ui.getCore().setModel(this.oDataModel, 'oDataModel');
//			sap.ui.getCore().getModel('oDataModel').refresh(true);

			//Set the JSON model to the core and refresh
			sap.ui.getCore().setModel(this.JSONModel, 'JSONModel');
//			sap.ui.getCore().getModel('JSONModel'); 

			//Change the view


		onExit: function() {
		//	sap.ui.getCore().getModel('JSONModel').refresh(true);
		//	sap.ui.getCore().getModel('oDataModel').refresh(true);



I am not quite sure if I have understood how you work with a odatamodel and setting it as a model for the core and so on, however this works and it updates the second view:


You can see that the Country table is loaded in the table at the bottom of the image. Ignore the panels over the table :D



], function(BaseController, JSONModel, formatter, Filter, FilterOperator) {
	"use strict";

	return BaseController.extend("DemoApplication.controller.table.TableViewContent", {

		formatter: formatter,

		onInit: function() {
			this.smartTable = sap.ui.getCore().byId("smarttable");

		onBeforeRendering: function() {
			var JSONModel = sap.ui.getCore().getModel('JSONModel');
		//	console.log(JSONModel);
		//	console.log(JSONModel);

			//Get the URI
			var sURI = JSONModel.oData.apiURL;
			this.oDataModel = new sap.ui.model.odata.ODataModel(sURI, true, JSONModel.oData.username + "@" +
				JSONModel.oData.instance, JSONModel.oData.password); 

			//Table chosen
			var sEntity = JSONModel.oData.table;

			//Fields to show
			var visibleEntityFields;

			//Checks whether the user have checked any specific columns or want all displayed.
			if (JSONModel.oData.chosenEntityFields.length === 0) {
				visibleEntityFields = JSONModel.oData.visibleEntityFields;
			} else {
				visibleEntityFields = JSONModel.oData.chosenEntityFields;

			//Set header
			//Set entity set

			//Set visible fields
			//Set ignored fields, which are the fields not allowed to call

			//Set model
			//	this.smartTable.getBinding("columns").refresh(true);
			//	this.smartTable.getBinding("items").refresh(true);
			//  this.smartTable.getModel().refresh(true);
			//  this.smartTable.rebindTable(true);


		onExit: function() {
			this.chosenParameters.length = 0; //Empty array
		//	this.smartTable.getBinding().destroy();




Please ignore all of the code commented out. It is just because I have tried different approaches and couldn't make anything work. Problem is now, when I push the arrow back to the previous view, choose another table or try to change any other field and come back to this view, only the header name of the table changes, but the columns and the loaded items stay the same:

I am sorry for this very long post, but I feel that you need all the code to be able to pinpoint what I am doing wrong.. I would really appreciate it, if soembody had the time to take a look and give me some help or directions.

Thank you very much in advance.

Best regards,


view-1.png (31.7 kB)
untitled-1.jpg (160.1 kB)
view-2-updates.jpg (163.3 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Alex Dalentzas
Feb 24, 2017 at 03:55 PM


In case you still have this issue, I have managed to solve the same problem by using the rebindChart(); method.

var chart = this.getView().byId("ItemsSmartChart"); 


10 |10000 characters needed characters left characters exceeded