Reputation: 273
I created a table and used an ODataModel
for the data binding. Everything is working fine. The template defines the properties which should be bound to the columns.
However, at some point I need to bind a JSONModel
to the table instead of the ODataModel
(because the data should be adapted but it should not actually be updated in the backend). The data should be just the same at the beginning.
So far I created the service request to get all the data. Then I added it to the JSONModel
(using the setData
function).
Now I wonder how to replace the two models. Is it even possible to change the binding (and table properties) so that the JSONModel
is bound or do I need to create a new table?
I am thankful for every hint!
Upvotes: 0
Views: 1872
Reputation: 6001
You can assign the new JSON model to the existing control using setModel member function:
oTable.setModel(yourNewJSONModel);
if you have named model (so, your binding looks like "{modelName>/property}" then you should assign new model this way:
oTable.setModel(yourNewJSONModel, "modelName");
Probably you have to rebind rows (or items) aggregation depending on the table kind you use (sap.ui.table.Table or sap.m.Table):
oTable.bindRows({
path: "/somePropertyPath",
model: "modelName"
});
If all the field names for rows are the same then it should work.
Upvotes: 1