cancel
Showing results for 
Search instead for 
Did you mean: 

How to disable cell in sap.m.table depends on another cell value?

0 Kudos

Hi Everyone.

i am developing SAPUI5 application using UI5 tables.i need to disable cell which is having values through javascript method,

screenshot from SAP standard screen. as like above table i need to disable some cells depends on the value.

can any one help me to find out the solution?

Thanks,

Ranjani Sekar.

Accepted Solutions (1)

Accepted Solutions (1)

Thank You All,

now its working as i expected. i have used below in View.js and i didn't write any method in controller.

oUOMTable.addColumn(new sap.ui.table.Column({

  label : new sap.ui.commons.Label({

  text : "Alt. UOM" }),

  template : new sap.ui.commons.ValueHelpField({maxLength:3 ,

  editable:{

  path: 'Meinh',

  formatter: function(Meinh){

  if (Meinh != null || Meinh ==''){return false;}

  else{return true;}

  }},

             }).bindProperty("value", "Meinh"),           

  sortProperty : "Meinh",

  filterProperty : "Meinh",

  width : "90px",

Answers (3)

Answers (3)

former_member227918
Active Contributor
0 Kudos

Hi Ranjani,

you can use below code also while defining input in to the table cell:

// input will be editable if value2 = X

<Input text="{value1}" editable="{= ${value2} == 'X' ? true : false}" />

Regards,

Akhilesh

francesco_alborghetti
Active Participant
0 Kudos

Assuming you are using sap.m.Input as template for the column you want to disable, you can format property "editable" of the control:


<Input

                    value="{b}"

                      editable="{path: 'a', formatter: '.editableFormatter'}"  />

in the controller:


editableFormatter: function (value) {

    if (value === 'editable') {

        return true;

      } else {

        return false;

      }

    }

Here a jsfiddle:

https://jsfiddle.net/falborgh/gstefkg0/

0 Kudos

Hi Francesco,

thank you for your reply. i am using Value help field so couldn't use editableFormatter method. but i have tried with this and no effect in screen.

above is my code in view.js page. on binding values to this table i need to disable this cell if it having value. if value is blank then it should be enable to enter value.

kindly give me your suggestion.

Thanks,

Ranjani Sekar.

francesco_alborghetti
Active Participant
0 Kudos

Hi Sekar,

sap.ui.commons.ValueHelpField extends TextField that has editable property, you can use formatter on it:

SAPUI5 SDK - Demo Kit

dunayevsky_yuri
Participant
0 Kudos

You might want to use a custom formatter function.

Here is an example of how your problem may be solved:

View:


<Table id="table">

     <columns>

          <Column/>

          <Column/>

     </columns>

</Table>

Controller:


onAfterRendering: function(){

var oData = {data: [

     {cell1: 1, cell2: "disabled"},

     {cell1: 2, cell2: "enabled"},

     {cell1: 1, cell2: "disabled"},

     {cell1: 1, cell2: "disabled"},

     {cell1: 2, cell2: "enabled"}

]};


this.getView().setModel(new sap.ui.model.json.JSONModel(oData), "model");

var oTable = this.getView().byId(this.createId("table"));

               

oTable.bindAggregation("items", "model>/data", new sap.m.ColumnListItem({

     cells:[

               new sap.m.Label({

                    text: "{model>cell1}"

               }),

               new sap.m.Input({

                    value: "{model>cell2}",

                    enabled: {

                         path: "model>cell1",

                         formatter: function(cell1){

                              if(cell1 === 1){return false}

                              else {return true}

                         }

                    }

               }),

          ]

     }))

}

Here is a working example:

JS Bin - Collaborative JavaScript Debugging

0 Kudos

Hi yuri,

thanks for your reply. i am working Value help field so i couldn't get this editableFormatter function with this control. do we have anything like this for Valuehelp field?