on 11-03-2015 1:09 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can also use insertItem function to have "ALL" item as a first selection - JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.m.Select
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");
var oSelect = this.getView().byId("idselect");
var newItem = new sap.ui.core.Item({ key: "all", text: "ALL"});
oSelect.setSelectedItem(newItem);
},
Well, please check source here -> https://jsbin.com/sajoju/edit?html,output
Two "fast (and dirty)" options how to add required item to Select object
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.