Client Side UTC to Locale

Client Side UTC to Locale

[Deleted User][Deleted User] Posts: 0Questions: 0Answers: 0
edited September 2012 in General
[code]$(document).ready(function() {
$('#data').dataTable({
"bProcessing": true,
"sAjaxSource": "/json",
"aaSorting": [[0,'desc']],
"bScrollInfinite": true,
"bScrollCollapse": true,
"sScrollY": "1024px"
});

$('tbody tr td:first-child').each(function() {
var utc = $(this).text();
var date = new Date(utc);
$(this).text(date);
});
});[/code]

I need some further processing done after/during the table is created. But with the second jQuery function doesn't seem to work, but if I do it after the building of the table (manually) it works.

Current data: 2012-09-05T14:17:38
Wanted data: Wed Sep 05 2012 09:17:38 GMT-0500 (Central Daylight Time)

Replies

  • [Deleted User][Deleted User] Posts: 0Questions: 0Answers: 0
    I think I found my answer in another post. http://datatables.net/forums/discussion/11551/call-back-outside-of-the-function
  • [Deleted User][Deleted User] Posts: 0Questions: 0Answers: 0
    [code]
    $(document).ready(function() {
    $('#data').dataTable({
    "bProcessing": true,
    "sAjaxSource": "/json",
    "aaSorting": [[0,'desc']],
    "bScrollInfinite": true,
    "bScrollCollapse": true,
    "sScrollY": "1024px"
    });

    $('#data').bind('init', function() {
    $(this).find('tbody tr td:first-child').each(function() {
    var utc = $(this).text();
    var date = new Date(utc);
    $(this).text(date);
    });
    });
    });
    [/code]

    New working code!! Waahoo!
  • [Deleted User][Deleted User] Posts: 0Questions: 0Answers: 0
    Well upon further inspect it works for the first set of dates, but after hitting the end and start of infinite scrolling there are dates not being converted.
  • [Deleted User][Deleted User] Posts: 0Questions: 0Answers: 0
    [code]
    $(document).ready(function() {
    $('#data').dataTable({
    "bProcessing": true,
    "sAjaxSource": "/json",
    "aaSorting": [[0,'desc']],
    "bScrollInfinite": true,
    "bScrollCollapse": true,
    "sScrollY": "1024px"
    });

    $('#data').bind('draw', function() {
    $(this).find('tbody tr td:first-child').each(function() {
    var utc = $(this).text();
    var date = new Date(utc);
    $(this).text(date);
    });
    });
    });
    [/code]

    Seems I may want to bind to 'draw' instead of 'init'. Fully working code.
This discussion has been closed.