Custom models can be used if none of the models provided by SAPUI5 is suitable for the specific needs of an application.
It is possible to create a custom model implementation for data sources that are not yet covered by the framework or are domain-specific. Keep in mind, however, that creating a custom model is highly complex and error-prone. We recommend using one of SAPUI5's predefined models whenever possible.
The subclassing of standard models is not supported in SAPUI5.
To instantiate a custom model, proceed as follows:
-
Extend the
Modelclass and specify the binding modes that the model should support (for example, two-way, one-way, one-time). -
Extend the
Bindingclass to suit your specific binding or reuse the existing specific binding implementationsPropertyBinding,ListBinding, and/orTreeBinding. -
To enable the filtering functionality, use the
Filterclass withFilterOperatorenum in your binding implementation. -
To enable the sorting functionality, use the
Sorterclass in your binding implementation.
You can find all necessary classes in the sap.ui.model namespace. As a starting point, take a look at the JSONModel implementation in sap.ui.model.json.JSONModel, which is available on the UI5 Open Source GitHub at https://github.com/UI5/openui5/blob/-/src/sap.ui.core/src/sap/ui/model/json/JSONModel.js.