How to sort by a column that is a function?

How to sort by a column that is a function?

jstuardojstuardo Posts: 105Questions: 42Answers: 0

Hello.... I have this definition for a column:

{
    data: function (row, type, val, meta) {
        if (row) {
            switch (row.sexo) {
                case 'M':
                    return 'Masculino';
                case 'F':
                    return 'Femenino';
                default:
                    return '';
            }
        }
    }
},

That column is orderable. When I press the column header to sort by that column, ordering column name that is posted to server is function. I need posted name to be sexo so that server can recognize it and order properly.

How can I do it?

Thanks
Jaime

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    I presume you are using server-side processing? If so do:

    data: 'sexo',
    render: function (data, type, row) {
      switch (data) {
       case 'M':
        // etc
      }
    }
    

    i.e. move the rendering into a columns.render function, rather than the data option, which should be set to the data point in the row you want to base the rendering on.

    Allan

Sign In or Register to comment.