Skip to Content

Adding a new Item in Select Box

Dear Experts ,

I implemented a select box (dropdown) by reading data from a northwind ODATA service and able to see the items in my dropdown.

Now I want to add an extra item "ALL" at the beginning . Can any body help me how can i do that .

Here is the code that i used to do this

View Code:

<Select id="idselect" items="{OdataModel>/Employees}"  change="somemthod">

  <core:Item  text="{OdataModel>FirstName}" key="{OdataModel>FirstName}"/>

  

  </Select>

Controller Code:

onInit: function()

{

  var oDataModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/Northwind/Northwind.svc");

         sap.ui.getCore().setModel(oDataModel,"OdataModel");

}

Kindly help with the code to create a new Item "ALL" in the Dropdown.

Thanks

Rizwan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 03, 2015 at 01:25 PM

    You can add item to select by calling function addItem JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.m.Select

    e.g.

    var oSelect = this.getView().byId("yourSelectId");
    var newItem = new sap.ui.core.Item({ key: "all", text: "ALL"});
    oSelect.addItem(newItem);
    

    see demo here - http://i.imgur.com/niGsfiz.gif

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 03, 2015 at 01:47 PM

    Hi Rizwan,

    <Select id="idselect" items="{OdataModel>/Employees}"  change="somemthod">

    <core:Item  text="All" key="A"/>

      <core:Item  text="{OdataModel>FirstName}" key="{OdataModel>FirstName}"/>

     

      </Select>

    Try this

    Thanks,

    KA

    Add comment
    10|10000 characters needed characters exceeded