cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Unique values to dropdown list from table

09-09-2014 7:01 AM
3060 views 6 comments
0 Likes
SAP Managed Tags
Subscribe

Hi ,

In above diagram i am if i select state in filter criteria dropdown , i can display all states in filter values.

But I am getting states from table results(/d/results) how can i get unique state values to the dropdown list without duplicates?

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member

Hi Jayasree.

In my point of view, the easier way to handle this is to create a model from the original Model like this


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

// attached request complete to the oData model and construct a new model

oData.attachRequestCompleted(function() {

     var data = this.getData()['d']['results'];

     var states = $.map(data, function(v, i) {

         return {name: v.state}; // assuming state is the attribute

     });

     stateModel.setData(states);

});

dropDownBox.bindItems('stateModel>/', new sap.ui.core.ListItem({

   key: 'stateModel>name',

   text: 'stateModel>name',

}));

dropDownBox.setModel(stateModel, 'stateModel');

-D

Former Member
0 Likes

hello experts, any other sample example about this ??

if yes, can anyone share the Link here ?

Thanks in Advance,

Bharath

Ankit_Maskara
Product and Topic Expert
Product and Topic Expert
0 Likes

Do as suggested by Krishnakant i.e. remove the duplicates in the resulting table from backend. To hint further, write code in the GET_ENTITYSET of the DPC_EXT method of corresponding service.

PS: You should open a new thread for your query.

BR.

former_member9607
Active Participant
0 Likes

Hi Jayasree,

Please write a logic in your method or RFC to delete duplicate entries from your return table.

Regards,

KK

Former Member
0 Likes

Hi Krishnakant,

   Thank u for replying, I can get duplicates to the table but i dont want to get duplicates to the dropdown list.....

former_member9607
Active Participant
0 Likes

Hi Jayasree,

Please correct me if i hv misunderstood the requirement.

You have a filter called state. Upon selection state in filter, U want the below dropdown should get reflected with values (distinct values) of state. Right?

If Yes, then writing DELETE ADJACENT DUPLICATE statement can be used to remove duplicate values from your table which returns the list of states.

so your /d/results will always have unique values and you will see unique values in your dropdown also.

Another way is, Take JSON model and get state data into it using .loadData() method.

After getting data into your JSON Model use the method .getData() to get the array.

Remove duplicates from your array and set it as datasource to your dropdown.

Hope it will help a bit.

Regards,

KK