UI5 / UI5/openui5

v2.ODataListBinding - Cannot change 'custom' parameter

Open
#2,492 4 comments 1 reaction 1 assignee View on GitHub

Nobody has claimed this yet.

enhancement in progress
Dominant language
JavaScript
Stars
3.3k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

This is a feature request.

Summary: It's not possible to change the parameters of class sap.ui.model.odata.v2.ODataListBinding after the object is created, more specifically the custom parameter.

Background [back end]: I created a CDS view for Material search and I'm fine-tuning a OData service using it. So, by using the custom search URL parameter, I can perform a fuzzy search based on material ID or name.

Example:
GET /sap/opu/odata/sap/YMY_SERVICE/Products?$top=20&search=1234

Background [front end]: I created a SelectDialog bound to this entity (Products) and I want to call the service passing the custom 'search' URL parameter using sap.ui.model.odata.v2.ODataListBinding

OpenUI5 version: 1.64.0
(but tested in 1.44.7)

Browser/version (+device/version): ANy

Any other tested browsers/devices(OK/FAIL): n/a

URL (minimal example if possible):

User/password (if required and possible - do not post any confidential information here):

Steps to reproduce the problem:

  1. Create a SelectDialog
<SelectDialog 
        title="Select Product" 
        search="onSearch" 
        items="{
			path: '/Products'
		}">
    	<items>
	        <StandardListItem 
		     title="{MaterialId}" 
	            description="{MaterialName}"  />
    	</items>
    </SelectDialog>
  1. Implement 'search' event handler
onSearch: function (oEvent) {
    var oParameters = oEvent.getParameters();
    var oListBinding = oParameters.itemsBinding;
    var sSearchTerm = oParameters.value;

    var oSource = oEvent.getSource();
    var oModel = oSource.getModel();

    var sCustomParams = oModel.createCustomParams({
        custom: {
            search: sSearchTerm
        }
    });
     // touching internal variable from class
    // this is what I would like to avoid
    oListBinding.sCustomParams = sCustomParams;

    // There is no alternative similar the one below
    /*
    oListBinding.setCustomParams({
     search: sSearchTerm
    });
    */

    oListBinding.refresh();
    
}
  1. The only way I could make things work without touching in the sCustomParams is by using a "manual" read to the oDataModel and transfer it to a JSONModel
onSearch: function (oEvent) {
    var oParameters = oEvent.getParameters();
    var oListBinding = oParameters.itemsBinding;
    var sSearchTerm = oParameters.value;

    var oSource = oEvent.getSource();
    var oModel = oSource.getModel();

    function onSuccess(oData, response) {
        this._oSomeJSONModel.setData(oData.results);
    }

    var mOptions = {
        urlParameters: {
            search: oParameters.value,
            "$top": 50
        },
        success: onSuccess.bind(this)
    };

    oModel.read("/Products", mOptions);
},

What is the expected result?
Have a method in class sap.ui.model.odata.v2.ODataListBinding to change custom parameters values.

What happens instead?
I had to touch the internal variable sCustomParams or replicate data to a JSONModel

Any other information? (attach screenshot if possible)
The same limitation happens for any other parameters of this class which are available in its constructor.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.