Sort is not working for Data Rendering for Certain Locales

Sort is not working for Data Rendering for Certain Locales

vnaid82vnaid82 Posts: 2Questions: 1Answers: 0

Sort is not working for Data for few locales:

Output Tags:
<td>
<c:OutputDate datetimevalue="{!dh.dhr.CreatedDate}" showtime="true"/>
</td>
<apex:outputpanel layout="none" rendered="{!NOT(isPartner)}">
<td class="dl-release-date">
<c:OutputDate datetimevalue="{!dh.dl.ReleaseDate__c}" />
</td>
</apex:outputpanel>

var dtf;
if ('{!userDateFormat}' != null || '{!userDateFormat}' != undefined ){
dtf = '{!userDateFormat}'; }
else{
dtf = '{!$Label.ExtrDateFormat}';
}
$.fn.dataTable.moment( dtf );
console.log('dtf>>' +dtf + '{!userLocal}');


dtf is supplied dynamically based on logged in users locale, Unfortunately it does not work for below, tried hardcoding the appropriate format displayed on UI, but then it wouldnt sort.


Console Log: dtf>>DD/MM/YYYY en_IN .
Even if I hard code DD/MM/YYYY into the $.fn.dataTable.moment( 'DD/MM/YYYY');
This sort works for most excluding HK, TR, RU locales. Not sure what am I doing wrong.

Answers

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921
    edited September 2019

    Start by looking at the Moment documentation. Your format is not correct for the dates you have in the "Release Date" column.

    for the day and month you have DD/MM. The Moment docs have this for MM for example: MM 01 02 ... 11 12. But you don't have leading 0s. Your format should beD/M/YYYY`.

    If this doesn't help then please post a link to your page or a test case replicating the problem so we can look directly at what you have.

    Kevin

  • vnaid82vnaid82 Posts: 2Questions: 1Answers: 0
    edited September 2019

    Kevin- Thank you very much, you are right. I altered the format and this started working.

    For the Date time Column, somehow it is sorting for few formats automatically even when that format is not supplies explicitly.

    Is there anyway to have moment js detect the format automatically without supplying the equivalent date format like I am trying to do.

    "columnDefs": [{ "orderable": false, "targets": [7] }] - I tried declaring here targets 3, datetime. but did not notice the sort order come into effect.

    Thanks in Advance.

  • kthorngrenkthorngren Posts: 21,160Questions: 26Answers: 4,921

    You can use multiple $.fn.dataTable.moment( 'D/M/YYYY'); to define multiple formats. Datatables has automatic type detection as described here. For the date formats not automatically detected you need to define them using $.fn.dataTable.moment(). As long as all the data in the column matches the same datetime format that format will be used for the column. If there are different formats in a column then it will be treated as text.

    HTH explain.

    Kevin

This discussion has been closed.