cancel
Showing results for 
Search instead for 
Did you mean: 

Copy / transfer data from OData model to JSON model

noahzemljic
Explorer
0 Kudos

Hello Experts

I am currently developing a SAPUI5 webapp for time evaluation. I am getting the data from the backend system, and it's being stored in an OData model. How can I copy that data into a JSON model (for filtering purposes)?
I have the following code:

onInit: function () {
		debugger;
		const oTable = this.getTable();
		const oItems = oTable.getBindingInfo("items").template;
		oTable.unbindAggregation('items');


		const oModel = this.getView().getModel();
		const oModelJSON = new sap.ui.model.json.JSONModel();
		oModel.read('/EmployeeSet', {
			success: function (oData, response) {
				oModelJSON.setData(oData);
				oTable.setModel(oModelJSON, 'JSONModel');
				oTable.bindItems(
					'/EmployeeSet',
					oItems
				);
			},
			error: function (oError) {
				console.log(oError);
			}

		});
		this.getView().setModel(oModelJSON);

		const oDatePicker = this.getView().byId('datum-auswertung');
		const sFormattedDate = this.formatDate('dd.MM.yyyy', new Date());
		oDatePicker.setValue(sFormattedDate);
	}
View Entire Topic
Tukutupap
Participant
0 Kudos

I think you got it, but it looks like the binding to your table is not correct. 2 quick things. If you are using sap.ui.table you can try bindRows instead, but if you are using sap.m.Table then you are good. Second thing is, you are naming your model so you would have to specify the name of the model in the binding, so instead of /EmployeeSet try JSONModel>/EmployeeSet.