Sorting Date Field in Salesforce
Sorting Date Field in Salesforce
Hi,
I am using DataTables in Salesforce. There is a standard date field that is formatted M/D/YYYY. However, when I try to sort the table it always sorts it by the first number in the date. I have tried using the normal sorting and I also tried to implement this as well: http://datatables.net/blog/2014-12-18
I don't have a link to provide as this is a VisualForce page within SFDC. I can confirm that other fields sort properly (e.g. Name, email, etc...)
Does anyone have any ideas on why it is not sorting properly?
This question has an accepted answers - jump to answer
Answers
The plug-in you linked to on the blog should do the business. Can you use the DataTables debugger on your table and let me know what the debug code is please. I would need the information from it, or a test case, to be able to say way it isn't working.
Allan
Here is the debugger info: https://debug.datatables.net/oqabaj
Here is an image of how the dates are currently being sorted: http://i.imgur.com/gK05vM3.png
What is confusing to me is if I build just a normal HTML table and have a column of date data, and format it the same way it is displaying in Salesforce, the default sorting works perfectly, without the moment.js plug-in.
Do I have to specify why type of data is in that column somewhere?
You have non-date data in the column:
That span means that DataTables can't detect the date format (since it isn't only date date).
Either you would need a custom sorting plug-in that will strip the HTML and then sort by date, or remove the span tag.
Allan
I see. Ok, I was able to generate the field value and not have SFDC put it in a <span> tag. Thanks for all your help Allan!