cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5: Value help in new line of a Table

mclb
Explorer
0 Kudos

Hi,

I'm using a sap.m.Table to display my table data.

To create a new row, I use a button in the headerToolbar, calling my function addComponent in the press event.

Most of the columns are simple sap.m.Text fields, there is just one sap.m.Input field, which should have a valueHelp. Therefore I set showValueHelp: true, valueHelpOnly: false, valueHelpRequest: this.onMaterialValueHelpRequest.

        addComponent: function(oEvent) {
            var oItem = new sap.m.ColumnListItem({
                cells : [ new sap.m.Input({
                    showValueHelp: true,
                    valueHelpOnly: false,
                    valueHelpRequest: this.onMaterialValueHelpRequested,
                    value: "{Material}"
                }), new sap.m.Text({
                    text: "{MaterialDescription}"
                }), new sap.m.Text({
                    text: "{Price}"
                }), new sap.m.Text({
                    text: "{PriceUnit}"
                }), new sap.m.Text({
                    text: "{RequirementQuantity}"
                }), new sap.m.Text({
                    text: "{RequirementQuantityUnit}"
                }), 
                    /*({
                showValueHelp : true
                
                })*/ new sap.m.Button({
                    icon : "sap-icon://delete",
                    press : [ this.deleteComponent, this ]
                }) ]
            });

            var oTable = this.getView().byId("idSalesOrderComponentsTable");
            oTable.addItem(oItem);
        },

I define the columns of the value help in a json file

{
    "cols": [
        {
            "label": "Material Number",
            "template": "Material",
            "width": "5rem"
        },
        {
            "label": "Description",
            "template": "Description"
        },
        {
            "label": "Category",
            "template": "Category"
        }
    ]
}

, which I load in the following way:

this.oColModel = new JSONModel(sap.ui.require.toUrl("at/develite/ui/sof/valuehelpdialog") + "/columnModelMaterial.json");

In my onMaterialValueHelpRequest function I try to get the columns, but thus.oColModel is undefined:

        onMaterialValueHelpRequested: function (oEvent) {
            var aCols = this.oColModel.getData().cols;
...

It seems this is the sap.m.Input field, for which I call the value help.

In all examples, I searched, it is possible to get the columns via this.oColModel...

The error message of in the browser conxole is "Uncaught TypeError: Cannot read property 'getData' of undefined".

Does anybody have an idea, how to fix my problem?

Thanks

Marcus

Accepted Solutions (0)

Answers (1)

Answers (1)

0 Kudos

Hi Marcus,

I assume this is the only error you are getting in your browser. Even if the control was unable to pull any data from the .json file at least an instance of JSON model with empty oData attribute would be created with the below statement and getData() should return either empty object or json data in the file.

this.oColModel =new JSONModel(sap.ui.require.toUrl("at/develite/ui/sof/valuehelpdialog") + "/columnModelMaterial.json");

Since, your error says "Cannot read property 'getData' of undefined", it means that no instance of this.oColModel is created. The statement was either not executed because of some conditional statement or it was specified in some other method other than onInit(). Therefore, please load the data to "oColModel" in onInit() function of your controller.

Hope this helps.

mclb
Explorer
0 Kudos

Hi Venkatesh,

thank you for your response.

this.oColModel is created in the onInit() of my controller without any condition. It is always created. When I set a breakpoint in the onInit(), I can see, that this.oColModel is created.

        onInit: function () {
            ...
            this.oColModel = new JSONModel(sap.ui.require.toUrl("at/develite/ui/ftc/valuehelpdialog") + "/columnModelMaterial.json");
        },

But in the valueHelpRequest it seems, that this is not the controller, it is the input field itself. So the oColModel is an attribute of the controller, and I try to use it from the input field. So, it's undefined, because the input field doesn't know oColModel.

In examples with value help in tables, where it is defined in the XML view, as valueHelpRequest they always set .methodName. In my add method of the controller, I cant give .methodName, this causes an error. I have to give this.methodName, maybe this is the problem? But the method is called, even when I call it with this.

I hope it is possible to understand, what I write here.

BR

Marcus

0 Kudos

Hi Marcus,

Sorry, I could not understand you completely. But, in the "addComponent" you mentioned "valueHelpRequest: this.onMaterialValueHelpRequested". Here, "this" is referring to the control in which onMaterialValueHelpRequested exisit. If "oColModel" is being instantiated in the same control in which "onMaterialValueHelpRequested" exist, then "this" should still reference the control when valueHelp is pressed. Only "oEvent" will reference the Input field. Please, check if this.oColModel is being modified anywhere in this or base controller.

Also, if you want to check if this is referring to controller or the input field. Try calling any of the other methods defined in the controller using "this" from onMaterialValueHelpRequested. If any of those methods are called, then it means this is referring the controller.

mclb
Explorer
0 Kudos

Hi,

I built a testMethod and tried to call it from my valueHelpRequest method:

        testMethod: function() {
            Log.info("testMethod");
        },
        onMaterialValueHelpRequested: function (oEvent) {
            this.testMethod();

Same result:

Uncaught TypeError: this.testMethod is not a function

And when I set a breakpoint at line this.testMethod() and take a look at this in the browser console, I get the following:

Looks for me, as it is the input field and not the controller?

BR

Marcus