/scripts/ahub.form.attachments.js
0

How to apply editable property to particular cell in sap.ui.table.Table ?

Feb 23, 2017 at 07:00 AM

65

avatar image
Former Member

Hi,

I need to edit a particular cell in the table.

Please help me on finding a java script code for this .

Now i can able to edit the entire column using editable.

 var oPriceProcedureTable = new sap.ui.table.Table({	
        id: "table-quotationcondition",
	editable: false,
	selectionMode: sap.ui.table.SelectionMode.Single,
	visibleRowCount: 8
 });

oView.getModel().read("/PriceProcedureSet", {
     success: function(oData) {
       var rowData = oData.results;

       var Staic_Feilds = [{
           "Fieldname": "conditionType",
           "Edit": false,
	   "ScrtextS": "Condition Type"
       }, {
	   "Fieldname": "unitPrice",
	   "Edit": true,
	   "ScrtextS": "Unit Price"
      }, {
	   "Fieldname": "quantity",
	   "Edit": false,
	  "ScrtextS": "Per"
      }];

      var Column_name = Staic_Feilds;
      var oModel = new sap.ui.model.json.JSONModel();

      oModel.setData({
         columns: Column_name,
         rows: rowData
      });

      that.oPriceProcedureTable.setModel(oModel);

      oPriceProcedureTable.bindColumns("/columns", function(sId, oContext) {
        var columnName = oContext.getObject().Fieldname;
        var Editable = oContext.getObject().Edit;
	var ScrtextS = oContext.getObject().ScrtextS;

        return new sap.ui.table.Column({
	        label: ScrtextS,
		template: new sap.ui.commons.TextField({
			value: {
				path: columnName
			},
			editable: Editable
	        })
        });
    });
}

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Akhilesh Upadhyay Feb 23, 2017 at 08:41 AM
0

ok,

but here in your code, editable flag is not setting from your backend value:

var Editable = oContext.getObject().Edit;

above line will return you the true/false from your static(column) data not from row data (oData.results[n].Edit).

you need to set editable property for textfield like below:

editable: "{Edit}" not editable: Editable

after this change should work, check this link may help you.

-Akhilesh

Show 2 Share
10 |10000 characters needed characters left characters exceeded

in my above code/link all cells of a row will be editable, sorry

pls check below link, where you need to define formatter function and inside this you need o make editable true/false depends on row and column index. as below:

template: new sap.ui.commons.TextField({
    value: {
        path: columnName,
        formatter: function(svalue) {
            if (svalue != null && svalue != "") {
                var _sPath = this.getBindingContext().getPath();
                var _colIndx = this.getCustomData()[0].getValue();
                var _rowIndx = _sPath.substr(_sPath.length - 1, _sPath.length);
                if (_rowIndx % 2 == 0 && _colIndx == 1) {
                    this.setEditable(true);
                } else {
                    this.setEditable(false);
                }
            }
            return svalue;
        }
    }
})

Example

-Akhilesh

1
Former Member
Akhilesh Upadhyay

Hi Akhilesh,

Thanks for the answer .

Here we have fixed row index , i.e either 0 2 4 ... , but the row index may vary depending upon the 'Edit' value.(i.e may be row index 1 , 3 or 4 etc) .

So i have edited your code to achieve this .

formatter: function(svalue) {
    if (svalue !== null && svalue !== "") {
        var _sPath = this.getBindingContext().getPath();
        var _colIndx = this.getCustomData()[0].getValue();
        var _rowIndx = _sPath.substr(_sPath.length - 1, _sPath.length);
        var Edit = this.getBindingContext().oModel.oData.rows[_rowIndx].Edit;
        if (Edit === "X" && _colIndx === 1) {
             this.setEditable(true);
        } else {
             this.setEditable(false);
        }
   }
   return svalue;
}
0
Akhilesh Upadhyay Feb 23, 2017 at 07:21 AM
0

how are you differentiating that cell ?

its depends on value or particular position of cell or anyother?

I think its good to have editable value for particular row cell from data itself from backend.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Feb 23, 2017 at 07:34 AM
0

Hi Akhilesh,

Thanks for your reply .

I need the second column of the table has to be edited , but not in all the rows

For example : if table has 5 rows

second column(Unit price has to be editable ) , but only in first and third row.

I can make the editable value for particular row cell from data itself from back end(oData.results[0].Edit;) , Here 0 is the row index , and Edit has the editable value.

Share
10 |10000 characters needed characters left characters exceeded
Skip to Content