+91 - 9000056459

+91 - 9030596677

Welcome to Skill Bricks

Thursday 6 October 2016

Factory Function Example using SAP FIORI

Posted by   on Pinterest

This is another example of factory function in which heterogeneous controls are added in same row.With the help of  factory function you can bind same row with heterogeneous property names.This is beauty of factory function.it plays very important role in table binding,list binding...etc.

Application Structure

SAP-Fiori

View Part

core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
  controllerName="view.S1" xmlns:html="http://www.w3.org/1999/xhtml">
 <Page title="Factory Function">
  <content>
 <Table id="tabId">
    <columns>
     <Column>
      <Text text="Name" />
     </Column>
     <Column>
      <Text text="Mobile" />
     </Column>
     <Column>
      <Text text="E-mail" />
     </Column>
    </columns>
          </Table>
  </content>
 </Page>
</core:View>

Controller Part

sap.ui.controller("view.S1", {
 onInit : function() {
  //calling method...........
  this.tableBindMethod();
 },
 // called method.................
 tableBindMethod : function() {
  var that = this;
  var json = new sap.ui.model.json.JSONModel("model/record.json")
  var tabId = this.byId("tabId");
  tabId.setModel(json);
  tabId.bindItems("/Records", function(Id, path) {
   return new sap.m.ColumnListItem({
    cells : [ new sap.m.Text({
     text : "{name}"
    }),

    // calling method..............
    that.factoryfunction(Id, path),

    new sap.m.Text({

     text : "{email}"
    }) ]
   })
  });
 },

  // called method.......
 factoryfunction : function(Id, Cpath) {
  var key = Cpath.getProperty("key");
  if (key === "L") {
   return new sap.m.Link({
    text : "{mobile}"
   })
  }
    else if (key === "C") {
   return new sap.m.CheckBox({
    selected : true,
   })
  } else if (key === "I") {
   return new sap.m.Input({
    value : "{mobile}"
   })

  } else {
   return new sap.m.Text({
    text : "{mobile}"
   })
  }
 }
});

record.json


 {"Records":[
 {
"name":"vikas Kumar",
"mobile":123,
"email":"v@gmail.com",
"key":"L"
},
{
"name":"Nikhil Kumar",
"mobile":111,
"email":"nik@gmail.com",
"key":""
},
{
"name":"Bhaskar Kumar",
"mobile":444,
"email":"Bhasker@gmail.com",
"key":""
},
{
"name":"Rohit Kumar",
"mobile":2222,
"email":"Rohit@gmail.com",
"key":"C"
},
{
"name":"Ram Kumar",
"mobile":133323,
"email":"Ram@gmail.com",
"key":""
},
{
"name":"Vishal Kumar",
"mobile":123123123,
"email":"vishal@gmail.com",
"key":""
},
{
"name":"raju Kumar",
"mobile":656566,
"email":"raju@gmail.com",
"key":"I"
}
]}

3 comments:
Write comments

Skill Bricks provides Online Training on vertical range of technologies utilizing State-of-art Infrastructure that resembles the professional environment