cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Adding a new field in v2 oDataModel binded to a sap.ui.table.Table / TreeTable in UI5 app.

nareshmallya
Explorer
496

Hi Everyone

I have an oData EntitySet "CUSTOMER_HIER_LIST" directly binded to sap.ui.table.TreeTable using v2 oDataModel and displays the treetable rows using treeAnnotationProperties binding. Now I want to initialize a new field called "IS_SELECTED" for each row. I have a sap.m.CheckBox in each row to which I will bind it. This field is not present in the CUSTOMER_HIERARCHY_LIST entity's metadata. I am not able to use Table.addSelectionRows() as I have a custom requirement for row selection.

In the 'dataReceived' event of the tree binding, if I try to do like below, then I see the error in the browser console as "Assertion failed: IS_SELECTED is not a valid property path" which is true because the field is not present in the entity set.

 

onCustomerListDataRecieved: function(oEvent){
  const oTreeTable = this.getView().byId("treeTableId"),
  aBindingContexts = oTreeTable.getBinding("rows").getContexts();
  aBindingContexts.forEach((oRowContext)=>{
     //This works because the field is present in entityset
     this.getModel("odataV2").setProperty("CUST_DESCR", "TEST CUSTOMER", oRowContext);
     //This does not work as the field is not present in entityset's metdata
     this.getModel("odataV2").setProperty("IS_SELECTED", false, oRowContext);
  });
}

 

I can change the value of an existing field, but then is it even possible to add a new field to v2 oDataModel as above?

Any suggestions and solutions will be greatly appreciated. 

Thanks,

Naresh




Accepted Solutions (0)

Answers (1)

Answers (1)

smarchesini
SAP Champion
SAP Champion
0 Kudos

Unfortunately, in the case of OData binding, my suggestion is to add the attribute to the CUSTOMER_HIER_LIST. You can create a dummy attribute (if it's in a CDS, it might look like this):
 

cast ( '' as BOOLE_D ) as IS_SELECTED

This should solve your issue.

Best regards,
Sebastiano

nareshmallya
Explorer
0 Kudos

Hi Sebastiano.
Thanks for your reply. We are using CAPM NodeJs for oData services. But the CUSTOMER_HIER_LIST is actually an external service from another deployed CAPM app. So I was wondering if we can use the above cds code in srv folder's cds file. We have the following definition currently.

 

using {  DealService as DS } from '../srv/external/DealService'; 

service camps @(requires: 'authenticated-user') {

entity CUSTOMER_HIER_LIST as projection on DS.CUSTOMER_HIER_LIST ;

 // ... Other service definitions
}