Custom Sort for DataTable Column Based on Another Property

Custom Sort for DataTable Column Based on Another Property

Eugene_BEugene_B Posts: 19Questions: 8Answers: 0

In my DataTable, one column has custom render logic, but its Sort has to happen directly based on the "reminderInfo" row property. This is not working.

"columns" : [        {
                "data" : "reminderInfo" /* also tried "sort" : "reminderInfo" */
                "render": function (data, type, row) {
                    if(row.reminderCount != null) {
                        return '<div class="reminder"><span class="fa-layers fa-fw fa-lg reminder-counter"><i class="fas fa-bell"></i><span class="fa-layers-counter">' + row.reminderCount + '</span></span>'
                                +'<div class="reminder-date">' + row.formattedLastReminderDate + '</div></div>';
                    } else {
                        return '';
                    }                      
                }
            }
        ],

The sorting does not follow the row's straight reminderInfo property.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    If you want sort to be different to display, then you need to handle that in your columns.render function, something like this: http://live.datatables.net/tolezupe/2/edit

    Colin

  • Eugene_BEugene_B Posts: 19Questions: 8Answers: 0

    The example provided doesn't have any custom sorting.

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.