Skip to content Skip to sidebar Skip to footer

Sapui5 JS In Controller Table Is Not Binding

Im trying to create search help using Odata service but my table is showing as undefined in controller, here is my code plz help index.html

Solution 1:

Your problem is how you are fetching the Id of your table.

Solution to your problem is :

var oTable = sap.ui.getCore().byId("pTab1");

However, let us understand the Id creation and fetching.

  1. In JS Views, there are two ways to create Ids.

    Way 1: : Provide direct Id. Eg:

    var oText = new sap.m.Text('idText'{ text:'Hey!'});

Now, this id -'idText' is associated with your entire application. So, if you have another view, which has a control with same id, you will see duplicate id error in console.

To fetch controls with ids creating with Way1, use the below method:

var oControl = sap.ui.getCore().byId('idText'); // since this is unique everywhere in your application.

Now, let us think 2 or more developers are working in an application and they are creating different views for the application. They may ( with high possibility), create controls with same id. The application will crash when we integrate both views due to duplicate id error. How to solve this?

Way 2: We can use the method createId() of the controller to create a Id for prefixed with view's id. So, this way even if two developers are using the same id, they will end up with different id for controls due to different view Id. So, let us think we have two views, View1 ( id: view1) and view2 ( id:view2).

If I create a control with same Id in both the controls (using createId() method of controller), two unique id will be generated and duplicate id error will never be raise.

So, View 1( id: view1):

var oText = new sap.m.Text(oController.createId('idText'),{ text:'Hey!'});

Id of oText in view 1 : view1--idText

Similarly,

View 2( id: view2):

var oText = new sap.m.Text(oController.createId('idText'),{ text:'Hey!'});

Id of oText in view 2 : view2--idText

Nicely done. But what if Id of view is auto generated and I might not know what is my view Id? Good question.

Solution is the method : this.byId(). In the cases, where id of controls are prefixed with view's id, always use the method this.byId(). It will append the view's id for you and then search and return the control unique to that view.

So, to fetch oText of View1, you will use (in View1's controller);

var oText = this.byId('idText')// will fetch view1--idText

Again to fetch oText of View2, you will use (in View2's controller);

var oText = this.byId('idText')// will fetch view2--idText
  1. IN XML Views, Id of controls are always prefixed with view's id by framework automatically. This is similar to our Way 2 of JS. ( Way 1 of JS is never possible in XML Views).

View code:

<Text id='idText' text='hey! /> <!-- Id generated is: 'viewid--idText' -->

Hence, when you use XML views, fetching of ID is always done by:

var oControl = this.byId('idText');

Solution 2:

I got the output list from odata service to the valuehelprequest table but not able to filter the data.

    sap.ui.define([
"sap/ui/core/mvc/Controller
      ], function(Controller) {
"use strict";

return Controller.extend("Xml_Search.controller.View1", {
 handlef4: function(){
    var oInput= this.getView().byId("Orderid");
    if(!this._oValueHelpDialog){
        this._oValueHelpDialog= new sap.ui.comp.valuehelpdialog.ValueHelpDialog("idValueHelp",{
        // supportRanges: true,
        key: "Orderid",
        descriptionKey: "OrderType",
        ok: function(oEvent){
            var aTokens= oEvent.getParameter("tokens");
            oInput.setTokens(aTokens);
            this.close();
        },
        cancel: function(){
            this.close();
        }
        });
    }
    var oColModel = new sap.ui.model.json.JSONModel();
    oColModel.setData({
        cols: [
                 {label: "Orderid", template: "Orderid"},
                 {label: "OrderType", template: "OrderType"},
                 {label: "Planplant", template: "Planplant"}
            ]
    });
    var oTable = this._oValueHelpDialog.getTable();
    oTable.setModel(oColModel,"columns");
            var oModel = new     sap.ui.model.odata.ODataModel("/Gateway_Order/sap/opu/odata/SAP/ZP01_FIORI_SRV_01/");
    oTable.setModel(oModel);
oTable.bindRows({path: "/OrderDataSet", filters:  [new     
sap.ui.model.Filter("Orderid",sap.ui.model.FilterOperator.EQ,null, oInput)]}
 );
this._oValueHelpDialog.open();
  }
});
});

Post a Comment for "Sapui5 JS In Controller Table Is Not Binding"