cancel
Showing results for 
Search instead for 
Did you mean: 

Radio Button Aggregation Binding

former_member602416
Participant
0 Kudos

Hi,

In my application i need to bind multiple cards to radio button which works fine when i use Radio button group but in addition i need to display one more radio button "New Card" which is static to the same group. This new card is not returned by the oData service.  At a time user should be able to select only one radio button either New Card or existing card which is returned by the odata service.

Can someone please help to understand how i can add the New Card to radio button group.

  //Create Radio Buttons to for Saved Cards

     var oCardRB = new sap.ui.commons.RadioButtonGroup({

      id: "CardRBG" ,

      tooltip : "Cards",

      select : function(){

      oController.Card();

      }   

     });

         

     var oItemTemplate1 = new sap.ui.core.Item({id: "CardItem"});

  

     oItemTemplate1.bindProperty("text", {

      parts: [

              {path: "CardModel>Card_holder_name", type: new sap.ui.model.type.String()},

              {path: "CardModel>Card_type", type: new sap.ui.model.type.String()},

              {path: "CardModel>Card_Key", type: new sap.ui.model.type.String()},

             ],

            formatter: function(Card_holder_name, Card_type, Card_Key ){

            return Card_holder_name +  " " + Card_type + " " + Card_Key ;

            }

     });

     oCardRB.bindItems("CardModel>/PaymentCardSet?$filter=UCRN%20eq%20'XXXXXX'", oItemTemplate1 );

     oCell1.addContent(oCardRB);

     oMatrix3.createRow(oCell1);

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member602416
Participant
0 Kudos

If i do like this then aggregation binding stop working. I think i need to add "New Card" as a new entry to the oData model fata so when i bind the radio button, new card come up automatically but don't know how to achieve it. any idea?

former_member182372
Active Contributor
0 Kudos

with direct odatamodel binding creating a blank entry on odata service is probably the only way. you can always copy odata to json model and add new entry, so up to your architecture.

former_member602416
Participant
0 Kudos

Hi Maksim,

Could you please provide the code snippet that how to create a new entry in oData service.

I tried to use oData.createEntry(sPath, vProperties), but it didn't work.

former_member182372
Active Contributor
0 Kudos

That should be done on GW side. I think it is better to jsut copy your OData call result to json model

former_member602416
Participant
0 Kudos

Hi Maksim,

I have copied the data into Json model but not able to merge a new entry into this model.

My first question is where to write the code to merge a new entry into model. It should be in Init function or onAfterRendering: function() because different people says different things.

I have a requirement where oData service could return the array when card details stored in the system or if there is no card details it will come back with no data. I need to create a new entry called "New Card" which should be a first radio button of the radio button group.

I have written below code which doesn't work

It returns only array of oData model(3 entry), new entry not added.

var oModel = sap.ui.getCore().byId("CardRBG").getModel("CardModel")

var jsondata = oModel.getData()

  jsondata.push({

  "UCRN" : "XXXXXXXXXXX",

  "BusPartner" : "XXXXXXXXXXX",

  "Card_Key" : "New",

  "Card_SequenceNumber" : "",

         "Card_Issue_Number" : "",

         "Card_Start_Date" : "",

         "Card_network" : "",

         "Card_security_code" : "",

         "Card_issuer" : "",

         "Card_type" : "",

         "Card_expiry_date" : "",

         "Card_holder_name" : "New Card",

         "Preferred_Card_Indicator" : false,

         "Process_Error" : "" });

  sap.ui.getCore().byId("CardRBG").setData(jsondata, true);

  sap.ui.getCore().byId("CardRBG").bindItems("CardModel>/results", oItemTemplate1);

I would appreciate for any help.

Thanks,

former_member182372
Active Contributor
0 Kudos

do that code just after you copy data from OData to Json models

var cardRBG = sap.ui.getCore().byId("CardRBG").

var oModel = cardRBG.getModel("CardModel");

var jsondata = oModel.getData();

  jsondata.results.push({

  "UCRN" : "XXXXXXXXXXX",

  "BusPartner" : "XXXXXXXXXXX",

  "Card_Key" : "New",

  "Card_SequenceNumber" : "",

         "Card_Issue_Number" : "",

         "Card_Start_Date" : "",

         "Card_network" : "",

         "Card_security_code" : "",

         "Card_issuer" : "",

         "Card_type" : "",

         "Card_expiry_date" : "",

         "Card_holder_name" : "New Card",

         "Preferred_Card_Indicator" : false,

         "Process_Error" : "" });

oModel.refresh();


cardRBG.bindItems("CardModel>/results", oItemTemplate1);

jamie_cawley
Advisor
Advisor
0 Kudos

Hi Swati,

The group has a function to add another item to it.

var myRadio = new sap.ui.core.Item({text:"one", key: "radio1"});

myRadioGroup.addItem(myRadio);

Regards,

Jamie

SAP - RIG