FIxed values on top of a column with formatted dates
FIxed values on top of a column with formatted dates

Hello,
I have a column with dates formatted as, e.g., 30 Oct 2020 with:
$.fn.dataTable.moment( 'DD MMM YYYY' );
The problem is that some of the cells are empty. I'd like the empty cells to be shown at the top, and then the rest of the data in ascending order.
Adding
var deadlineType = $.fn.dataTable.absoluteOrder( [
{ value: '', position: 'top' }
] );
[...]
"columnDefs": [
{ "targets": 2, type: deadlineType } ]
to my code puts the empty cells on top; nevertheless the sorting is messed up, I suspect because the sorting is made for text. Nevertheless, $.fn.dataTable.absoluteOrderNumber doesn't work either. Is there and absoluteOrder plugin for dates formatted as mine?
This question has accepted answers - jump to:
Answers
Take a look at this thread that I just answered. See if the proposed solution will work for you.
Kevin
Thank you very much. My data is provided server-side, not via ajax call. Not sure if this is why my code isn't working properly. I'm using this:
The column with the dates is column 2. Nevertheless I get the dates in my first column (where other data should be), and they're also not formatted as I want (e.g. 'Thu Dec 31 2020 00:00:00 GMT+0000'). What am I overlooking?
Here is an example:
http://live.datatables.net/caqozaze/1/edit
It shows that the absolute order you tried isn't working because Datatables type detection sets the column type as string. For none date data we set a fake date value then use it with the absolute plugin to sort by that fake value. The last date column is just normal just to show the
$.fn.dataTable.moment( 'DD MMM YYYY' );
format is working.Kevin
You can use the datetime render to change the format.
Kevin
Yes, thanks. The main issue though is that it's in the wrong column!
Hmm. Not sure why the data would be in the wrong column. Can you post a link to your page or a test case replicating the issue so we can take a look?
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Ah, I didn't see your live example. That's now working, thank you so much!