DataTables / DataTablesSrc

DataTables source repository
https://datatables.net
MIT License
628 stars 423 forks source link

Feature request: add "sort" or "sortBy" key for sorting columns that may contain HTML data as the contextual state #224

Closed sts-ryan-holton closed 2 years ago

sts-ryan-holton commented 2 years ago

I'm using quite a few features of the newest DataTables version. I'm using the render function to return formatted data, and am using the the data key of each column to inject the column's data.

The issue I'm facing, is that my presentCellContents function can return data including HTML and then my sorting (for example, highest to lowest) is then. lost as there's HTML in the cell.

I thought DataTable's always used the data key in this context for sorting?

I'd like to see a feature where I could add potentially.a sort or sortBy key which would determine what to sort by regardless of the contents of the cell, for example, I have a "sessions" key which indicates how many times a user has landed on my web page, so I'd like to be able to sort on this regardless of any HTML returned in my render function.

columns: [
  {
    data: 'revenue',
    className: 'td-col cell--revenue',
    visible: (ROLE_ID == 2) ? true : false,
    searchable: (ROLE_ID == 2) ? true : false,
    render: function (data, type, row, meta) {
      return presentCellContents(data, row, 'revenue', 'currency')
    }
  }
]
AllanJard commented 2 years ago

What you describe sounds like what we call orthogonal data if I've understood correctly. Have a condition on the type parameter to return different data for the different actions DataTables performs.

In future, could you post support requests in the DataTables forum, as the template issue text requests:

Please post support requests and questions in the DataTables forums at https://datatables.net/forums. Support requests posted here will be closed. The intention of this request is to allow all questions to be located in a single, searchable, location.