cancel
Showing results for 
Search instead for 
Did you mean: 

Bind sap.m.StandardListItem "Selected" Property from odata boolean Result "X"

sanjoy0308
Active Participant
0 Kudos

I was trying to bindItems in a sap.m.List of sap.m.StandardListItem, but was not able to make sap.m.ListMode.MultiSelect selected if one parameter is coming "X". In filter if we use this boolean check then false results will not be shown in output. To show in a Dialog the list with selected StandardListItem, I used bindProperty and it works. Here is my code example:

Code Snippet

var itemTemplate = new sap.m.StandardListItem({

  title : "{SrvTaskDesc}", // string

  });

  itemTemplate.bindProperty("selected", "IsenbDisInd", function(bValue) {

     return bValue == "X" ? true : false;

  });

  retMethList = new sap.m.List({

  mode : sap.m.ListMode.MultiSelect,

  });

  url = location.protocol+"//"+dynamicHost+":"+dynamicPort+"/sap/opu/odata/XXX/XXXXXXX/";

  oModel = new sap.ui.model.odata.ODataModel(url, true);

  retMethList.setModel(oModel);

  params = ",C" + ","

  + sap.ui.getCore().getModel("userModel").getData().plant + ",,,,"

  + "";

  filter = new sap.ui.model.Filter("IAllparam", sap.ui.model.FilterOperator.EQ, params);

  retMethList.bindItems("/getGlobalTaskList",itemTemplate,null,[filter]);

  new sap.m.Dialog({

  title : "Sanjoy Saha", // string

  content : retMethList, // sap.ui.core.Control

  leftButton : new sap.m.Button({

  text : "CANCEL",

  type : sap.m.ButtonType.Reject,

  icon : sap.ui.core.IconPool

  .getIconURI("sys-cancel"),

  press : function() {

  this.getParent().close();

  }

  }),

  rightButton : new sap.m.Button({

  text : "SAVE",

  type : sap.m.ButtonType.Accept,

  icon : sap.ui.core.IconPool.getIconURI("save"),

  press : function() {

  this.getParent().close();

  }

  }),

  afterClose : [ function(oEvent) {

  var control = oEvent.getSource();

  }, this ]

  }).open();

Here IsenbDisInd is the field which is coming from odata as "X" or "" as output and based on that ListItem is selected or deselected.

Accepted Solutions (0)

Answers (1)

Answers (1)

karthikarjun
Active Contributor
0 Kudos

Will this helpful for you? https://jsbin.com/xaketa/edit?html,js,output

//Code:

//Model

var data = [{

  "title" : "SSE",

  "selected" : "X"

},

           {

  "title" : "SE",

  "selected" : "Y"

}];

var model = new sap.ui.model.json.JSONModel(data);

sap.ui.getCore().setModel(model);

//Control

var itemTemplate = new sap.m.StandardListItem({

  title : "{title}",

  selected : {

    path : "selected",

    formatter : function(oEvent){

      return oEvent=="X" ? true : false;

    }

  }

 

  });

  var retMethList = new sap.m.List({

  mode : sap.m.ListMode.MultiSelect

  });

retMethList.bindItems("/",itemTemplate);

retMethList.placeAt("content");

Regards,

Karthik A