avatar image
Former Member

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

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
	        })
        });
    });
}

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Feb 23, 2017 at 08:41 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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;
      }
  • Feb 23, 2017 at 07:21 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 23, 2017 at 07:34 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

Skip to Content