cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling buttons (enable/disable) in sap.m.table based on another property

Former Member
0 Kudos
5,588

Hi,

I am developing a master-detail SAPUI5 application that contains sap.m.table in details page with sap.m.button "Accept" for each row.

The requirement is this button should be enabled based on another property from ODATA response.

In the below code, i am creating a template with 3 columns as label & 4th column as button. This button should be enabled based on a property " Acceptance" that is returned from ODATA response. If the row is accepted, i should disable the button & if not, enable the button.

The problem is i will not have "Acceptance" property value till i do the binding. Looking into another forum, i found that there is a bindProperty() that gets called for each row & an object can be controlled through that. But, here also i am not able to get the Property value "Acceptance".

can anyone pls suggest how i can fetch the value of Acceptance & control this button enable/disable? I also tried calling a controller function from bindProperty, that also dint help.

pose_table.bindAggregation("items", {

     path : "/ServiceEntrySheet",

  

     template: new sap.m.ColumnListItem({

         cells: [

                 new sap.m.Label({ text: "{SheetNo}" }),               

                 new sap.m.Label({ text: "{GrossVal}" }),               

                 new sap.m.Label({ text: "{Currency}" }),

                 new sap.m.Button("se_accept_btn",{

                

                  text : "Accept",

            press : oController.approve,

            visible : true,

            //enabled : true,

                

            }).bindProperty("enabled", "/ServiceEntrySheet",function(){

            var sheetNumber = "{SheetNo}";

            alert(sheetNumber);

            /*alert("accept button="+cellValue);

            if("{Acceptance}"=="X"){

            //alert("accepted ="+cellValue);

            this.setEnabled("false");

            this.setText("Accepted");

            }else{

            //alert("not accepted ="+cellValue);

            enabled: true;

            }*/

            }),

         ]

     })

  });

Dharini.,

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos
Hi,

first off .setEnabled requires a boolean not a string; e.g .setEnabled(false);
you can get the property directly from the Model:
property = sap.ui.getCore().getModel().getProperty("/ServiceEntrySheet/Acceptance");
//note: path might be different (i dont know exactly how your Odata response looks like)

Also if you create more than one Item via this method doesn't  new sap.m.Button("se_accept_btn"...) cause an issue
since sapui only allows unique ids for objects?
I could also suggest using a factory method for creating the items like:
I personally always create items like this and this alway works for me