Sorting Suggestion
Sorting Suggestion
Been a while since I messed with DataTables, but just ran into an issue where a Date/Time was rendering in a column and wrapping was sometimes happening between the time and the AM/PM. Changed the space to an NBSP; and of course that broke sorting.
I see the sorting plugin, but had a suggestion for a much simpler approach: support a data attribute on a TD that gives it the value to use for sorting. If that exists, assume the value within the cell is just a display value. Would be very simple to deal with, no plugin necessary.
Replies
If you are using the DataTables stylesheet just add
nowrap
as a class to your table.Otherwise simply add the following to your CSS:
This is already available. Documentation / Example.
Allan
Well, that forces no wrapping which isn't what I really needed. My table was getting too wide as it was.
Here are the 3 steps I used to solve it under the current design:
In the initialization "columnDefs":
Function to force wrapping between date and time (could have been done server side given this is an MVC app):
Function to deal with sorting a date time that has an html BR tag:
Obviously I was experimenting so you can optimize the code
Sorry - I misunderstood. I thought you didn't want wrapping. You could use a column specific class if you only want the no wrapping to occur on the time column.
However, the orthogonal data is probably the best way as you suggested.
Allan
I do appreciate your time & attention, Allan
Note to HTML purists: I did not add the break tag in the customary way "<br /> because it was coming back out as "<br>" anyway.