on 04-13-2016 4:49 AM
Hello Experts,
Is there any way to display Unique values in Combo box ??
Here is my Combobox code
<l:VerticalLayout>
<l:content>
<Label text="LOCATION:" class="LabelStyle"/>
<ComboBox id="idCombo" placeholder="Slect Your Location" items="{OdataModel>/Location_details}" selectionChange="onChange">
<core:Item text="{OdataModel>LM_LOCATION_ID_PK}"/>
</ComboBox>
<Label text="DATE:" class="LabelStyle"/>
<ComboBox id="oComboBox" selectionChange="onSelect"></ComboBox>
</l:content>
</l:VerticalLayout>
Can anyone Help me ?
Thanks in Advance,
Bharath
Bharath,
this is usually because of your odata svc view is returning those duplicates... unfortunately, I do not think odata can do distinct.. this will need to be addressed on your db view itself.
as Sarbjeet mentioned, check your odata output and get the view corrected.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sergio .!!
here is the code
<script id="view1" type="sapui5/xmlview">
<mvc:View
height="100%"
controllerName="sap.m.sample.ComboBox.Page"
xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Page showHeader="false">
<content>
<ComboBox
items="{
path: '/SENSOR_DETAILS1',
sorter: { path: 'SO_TEXT_DT_MM_YYYY' }
}">
<core:Item text="{SO_TEXT_DT_MM_YYYY}" />
</ComboBox>
</content>
</Page>
</mvc:View>
</script>
<script>
sap.ui.controller("sap.m.sample.ComboBox.Page", {
onInit: function (oEvent) {
// set explored app's demo model on this sample
var oDataModel1 = new sap.ui.model.odata.ODataModel('http://xx.xx.xx.xx:8000/AC_ANALYTICS/Power111.xsodata/',true);
oDataModel1.setSizeLimit(15000);
this.getView().setModel(oDataModel1);
}
});
var oView1 = sap.ui.xmlview({
viewContent: jQuery('#view1').html()
});
oView1.placeAt('id1');
</script>
Regards,
Bharath
in your browser, go to your service end point and see if you have duplicates
http://xx.xx.xx.xx:8000/AC_ANALYTICS/Power111.xsodata/SENSOR_DETAILS1?$format=json&$orderby=SO_TEXT_DT_MM_YYYY
see if the duplicates exist...
if you do not have access to fix the view. you will need to do it on a json object... (I dont recommend this approach.. you should try to get the view fixed instead)
Use an intermediate json model.
get all the values in array and then use function (https://api.jquery.com/jQuery.unique/) unqiue and then map it to combobox using json model.
Regards,
Sarbjeet Singh
Thank you Sarbjeet,
Your idea worked for me and able to remove duplicates using below code
<mvc:View
height="100%"
controllerName="sap.m.sample.ComboBox.Page"
xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Page showHeader="false">
<content>
<ComboBox
items="{
path: '/d/results',
sorter: { path: 'SO_TEXT_DT_MM_YYYY' }
}">
<core:Item text="{SO_TEXT_DT_MM_YYYY}" />
</ComboBox>
</content>
</Page>
</mvc:View>
</script>
<script>
sap.ui.controller("sap.m.sample.ComboBox.Page", {
onInit: function (oEvent) {
// set explored app's demo model on this sample
/*var oDataModel1 = new sap.ui.model.odata.ODataModel('http://xx.xx.xx.xx:8000/AC_ANALYTICS/Power111.xsodata/',true);
oDataModel1.setSizeLimit(15000);
this.getView().setModel(oDataModel1); */
var url3 = "http://xx.xx.xx.xx:8000/AC_ANALYTICS/Power111.xsodata/SENSOR_DETAILS1?$select=SO_TEXT_DT_MM_YYYY&$or...";
var salesModel3 = new sap.ui.model.json.JSONModel();
//var salesModel3=new sap.ui.model.odata.ODataModel();
salesModel3.setSizeLimit(15000);
salesModel3.loadData(url3);
this.getView().setModel(salesModel3);
}
});
now i have two combobox, and one is dependent on another.! if i use two different JSON models for two combobox, the values are not filling
any suggestions for this ?
Thanks in Advance,
Bharath
hi
Your code looks fine.
But screenshot you have given is for quarter and code is for location.
Also check the odata output of the call which is filling the combobox.
Also, compare your code syntax with the code here
Regards,
Sarbjeet Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sarbjeet,
Thanks for the reply,
Am using the same code, but still am getting repeated values
here is the code
<script id="view1" type="sapui5/xmlview">
<mvc:View
height="100%"
controllerName="sap.m.sample.ComboBox.Page"
xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m">
<Page showHeader="false">
<content>
<ComboBox
items="{
path: '/SENSOR_DETAILS1',
sorter: { path: 'SO_TEXT_DT_MM_YYYY' }
}">
<core:Item text="{SO_TEXT_DT_MM_YYYY}" />
</ComboBox>
</content>
</Page>
</mvc:View>
</script>
<script>
sap.ui.controller("sap.m.sample.ComboBox.Page", {
onInit: function (oEvent) {
// set explored app's demo model on this sample
var oDataModel1 = new sap.ui.model.odata.ODataModel('http://xx.xx.xx.xx:8000/AC_ANALYTICS/Power111.xsodata/',true);
oDataModel1.setSizeLimit(15000);
this.getView().setModel(oDataModel1);
}
});
var oView1 = sap.ui.xmlview({
viewContent: jQuery('#view1').html()
});
oView1.placeAt('id1');
</script>
any suggestion now ??
Thanks in Advance.??
Bharath
User | Count |
---|---|
87 | |
10 | |
9 | |
9 | |
9 | |
6 | |
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.