Can't sort column defined by a render function

Can't sort column defined by a render function

xecollonsxecollons Posts: 1Questions: 1Answers: 0

Hello,

I have this on columnDefs of a datatable in my js script:

columnDefs: [
            {...}, //other columns that don't use render and work great
            {...},
            {
                "render": function (data, type, row) {
                    return data === true ? '<div align = "center"><span class="glyphicon glyphicon-ok"></span></div>' :
                        '<div align = "center"><span class="glyphicon glyphicon-remove"></span></div>'
                },
                "targets": 2
            }

As you can see, I have a boolean and use one glyphicon if this boolean is true, and another if it's false. Glyphicons work great, datatable draw them perfect. The problem comes on sorting, when I press the sort arrows, it doesn't sort. It doesn't give an error message or anything, it just doesn't sort correctly. I don't know how to make it sort well, something like "sort":data or anything like that. Any help would be appreciated.

Answers

  • loderunnerloderunner Posts: 1Questions: 0Answers: 0

    In case it helps, I also wondered how to sort on a rendered column. In my case, I was rendering the data into an img specification. For presentation purposes, I want an IMG. For sorting purposes, I want to sort on the original raw data value.

                      "render": function ( data, type, row ) {
                        if ( type === "sort" || type === 'type' ) {
                          return data;
                        }
                        else {
                          return "<img src='media/images/" + row.c_Status + ".gif' >";
                        }
    
  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Looks good to me. Also check out the orthogonal data manual page.

    Allan

This discussion has been closed.