jQuery DataTables – Sort by object’s property


One of my table’s columns needs to render a link based on several object’s properties. It’s simplified definition would look something like this:

columns: [{
    "data": "obj",
    "render": function(data, type, row) {
        return "<a href='" + obj.x + "'>" + obj.y + "</a>";
} ... ]

It does render as intended, although I would also like the column to be sortable by obj.y property. This is where my problem begins, as I found the mechanics a little bit confusing, but maybe hopefully I just keep missing some obvious solution.

I’ve attempted to add my custom sorting to jQuery.fn.dataTableExt.oSort, and then set the column’s sType, and else to add data-order/data-sort attribute to each cell during rendering, but neither of those worked – the column still seems to apply it’s default ordering.

Is there any recommended approach I should try?
I’m using plugin’s version 1.10.

Link: jQuery DataTables – Sort by object’s property
Source: Stack Jquery


About Author

Leave A Reply