cancel
Showing results for 
Search instead for 
Did you mean: 

Table - add row dynamically, formatter issue

former_member182374
Active Contributor
0 Kudos

Hello Experts,

I'm having a table in my SAPUI5 application.

The table has an "Add Row" button in each row which supposed to insert a new row below the current row.

If I'm not using a formatter function it works but if I'm using a formatter there is a strange behavior, see screenshots:

1. Initial View

2. Added 2 (empty) rows

3. Enter values in the rows

4) When pressing the "+" I'm expecting that both "3" and "4" will go down but only "3" goes down.

jsbin:

http://jsbin.com/papata/1/edit?html,output

If I'll comment the formatter function it'll work.

What am I doing wrong?

Regards,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

former_member182862
Active Contributor
0 Kudos

Hi Omri

I have fixed your code here. And few things

1. we are responsible to update the model if we have formatter. See the change handler that I have added

2. you do not need to bind model to table again once it is set in global. BTW, you have oTable.setModel(sap.ui.getCore().getModel("tblModel")); which is incorrect. It should be

oTable.setModel(sap.ui.getCore().getModel("tblModel"), 'tblModel') if you really wan to; Anyway, this is not need because UI5 will look it up in the global model.

Thanks

-D

former_member182374
Active Contributor
0 Kudos

Thanks Dennis for both your answer and explanation.

Regards,

Omri

Answers (1)

Answers (1)

former_member189945
Contributor
0 Kudos

Hi Omri,

Try to move the formatter function next to path inside parts definition. That should fix it.

bindProperty("value", {

                        parts: [

                                {path : "tblModel>anotherText",

                                formatter : function(anotherText) {

                                if ((anotherText!=null) && (anotherText.trim().length>0)) {

                                    return "X" + anotherText;

                                } else {

                                    return anotherText;

                                }

                            }}

                        ],

                    // What is wrong with the formatter?

                    /*formatter : function(anotherText) {

                        if ((anotherText!=null) && (anotherText.trim().length>0)) {

                            return "X" + anotherText;

                        } else {

                            return anotherText;

                        }

                    }*/

Here's the jsbin: http://jsbin.com/gikoxejagidu/1/edit

Regards,

Kimmo

former_member182374
Active Contributor
0 Kudos

Hi Kimmo,

I've moved the formatter to the 'path' section.

The row is added correctly but the formatter is not applied...

Regards,

Omri

former_member189945
Contributor
0 Kudos

Yes you are correct. That doesn't work. Please, post a solution if you get it working.

Regards,

Kimmo