Sort by source data and not by display data

Sort by source data and not by display data

freddydfreddyd Posts: 5Questions: 1Answers: 0
edited April 2020 in Free community support

Description of problem:
Description of problem:
I'm loading some data from ajax. What I'm trying to achieve is transform some properties to show them, but order the information based on the original data. I need to clarify that I'm using the ajax option but not the server-side.

Here are my options:

{
    processing: true,
    searchDelay: 600,
    ajax: {
        URL: "...",
        dataSrc: ""
    },
    ...
}

This is the method I am using to transform the data to show:

columnDefs: [{
    "targets": [ 0,1,8,9 ],
    "orderable": false,
},{
    "targets": 2,
    data: "country.code",
    render: function(data, type, full, meta){
        return <span title='${full.country.name_by_language}'><img src='${full.country.flag_path}'></span>;
    },
}]

I also have to clarify that if I use the server-side, it works perfectly and make sorts using the data property

Answers

  • kthorngrenkthorngren Posts: 21,311Questions: 26Answers: 4,948

    Take a look at the Orthogonal Data docs. If I understand correctly you will only want to return the span for the display operation, something like this:

        render: function(data, type, full, meta){
            if ( type === 'display' ) {
                return <span title='${full.country.name_by_language}'><img src='${full.country.flag_path}'></span>;
            }
            return data;
        },
    

    Kevin

  • freddydfreddyd Posts: 5Questions: 1Answers: 0

    Thanks. Works as i expected!!

This discussion has been closed.