Skip to Content

How to remove duplicates and display only unique values in ViewSettingsItem?

Hello experts,

I am getting duplicate values in JSON format from backend and I want to remove the duplicate values and display only unique values in SAPUI5 ViewSettingsItem.

XML View:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<ViewSettingsDialog >
    <filterItems>
                <ViewSettingsFilterItem>
            <items>
                <ViewSettingsItem text="{Status}" key="{sId}"/>
            </items> 
        </ViewSettingsFilterItem>

    </filterItems>
</ViewSettingsDialog>

JSON Data:

{
"d": {
    "results": [{       

        "Status": "Completed",
        "sId": "C1"
    }, 
    {       

        "Status": "Completed",
        "sId": "C1"
    },
    {       

        "Status": "Started",
        "sId": "S1"
    },
    {       

        "Status": "In Process",
        "sId": "P1"
    },{     

        "Status": "Completed",
        "sId": "C1"

    }]
}

Please guide me in this.

Add comment
10|10000 characters needed characters exceeded

  • I would prefer this to be filter at backend but still if you want to do frontend try as follow.

    a = your JSON;
    var uniqueValues = a.d.results.filter((currentVal,index) => { return index === a.d.results.findIndex( current => { return JSON.stringify(current) === JSON.stringify(currentVal);});});
  • Get RSS Feed

1 Answer

  • Apr 13 at 07:28 PM

    ask backend guy to remove

    if you know coding, you can also do it in frontend, but not that recommended.

    Add comment
    10|10000 characters needed characters exceeded