cancel
Showing results for 
Search instead for 
Did you mean: 

How to Display a Unique Values in XML views Combo box.?

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

SergioG_TX
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

SergioG_TX
Active Contributor
0 Kudos

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)

gill367
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Am not getting any Duplicates from this query.!

but still how to fix this issue ???

Regards,

Bharath

Former Member
0 Kudos

it looks very difficult to achieve this for beginners like me

any other suggestions or better example than this will helps me a lot

Regards,

Bharath

Former Member
0 Kudos

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

gill367
Active Contributor
0 Kudos

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

SAPUI5 Explored

Regards,

Sarbjeet Singh

Former Member
0 Kudos

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