DarX
DarX

Reputation: 25

Get Distinct data from SharePoint List and push in in table

I have a code that take value from SharePoint List and display it on table. Below is the code:

$(document).ready(function() {    
getItems();    
});  


function getItems() {  

$.ajax({  

    async: true,  
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('Global')/items?$filter=Title eq Domain",  
    method: "GET",  

    headers: {  
        "accept": "application/json;odata=verbose",  
        "content-type": "application/json;odata=verbose"  

    },  
    success: function(data) {  
        data = data.d.results;  
        console.log(data);  
        $.each(data, function(index, value) {  

            if (value.Title == null) {
                value.Title = "";}
            else{
                value.Title = value.Title ;}

            if (value.Grouped_x0020_OPUs == null) {
                value.Grouped_x0020_OPUs = "";}
            else{
                value.Grouped_x0020_OPUs = value.Grouped_x0020_OPUs;}       


            if (value.Phase == null) {
                value.Phase = "";}
            else{
                value.Phase = value.Phase ;}

            if (value.Stage == null) {
                value.Stage = "";}
            else{
                value.Stage = value.Stage ;}


            var html = "<tr><td>" + value.Title + "</td><td>" + value.Grouped_x0020_OPUs + "</td><td>" + value.Phase + "</td><td>" + value.Stage + "</td></tr>";  
            $('.table tbody').append(html);

        });

        table = $('#table_id').DataTable();

    },  
    error: function(error) {  
        console.log(JSON.stringify(error));  

    }  

})  


}

The code above will take all the value in the list. My question is how do I get a value from the list such as value.Grouped_x0020_OPUs and remove the duplicate one then display it on table?

Please help me on this. Thank you very much.

Upvotes: 1

Views: 317

Answers (1)

Tany3450
Tany3450

Reputation: 338

This is not supported. Please refer here. You can try using caml with group by clause or you can implement your own client side logic like this;

var groupedOPUs= []; //should be declared at the beginning of the success function.
if (groupedOPUs.indexOf(value.Grouped_x0020_OPUs) < 0){
        var html = "<tr><td>" + value.Title + "</td><td>" + value.Grouped_x0020_OPUs + "</td><td>" + value.Phase + "</td><td>" + value.Stage + "</td></tr>";  
        $('.table tbody').append(html);
        groupedOPUs.push(value.Grouped_x0020_OPUs);
}

Upvotes: 1

Related Questions