Sorting Date Field in Salesforce

Sorting Date Field in Salesforce

hyzamhyzam Posts: 4Questions: 1Answers: 0
edited February 2015 in Free community support

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

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    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

  • hyzamhyzam Posts: 4Questions: 1Answers: 0

    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

  • hyzamhyzam Posts: 4Questions: 1Answers: 0

    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?

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Answer ✓

    You have non-date data in the column:

    <span id="j_id0:j_id3:j_id4:example:5:j_id36">9/4/2001

    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

  • hyzamhyzam Posts: 4Questions: 1Answers: 0

    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!

This discussion has been closed.