Author Topic: Formating date inside grid to Jan. 01, 2016 11:32 AM format?  (Read 5188 times)

Eagle_f90

  • Newbie
  • *
  • Posts: 15
    • View Profile
Formating date inside grid to Jan. 01, 2016 11:32 AM format?
« on: January 22, 2016, 08:57:13 pm »
I have a few dates to display in the grid that are coming from some JSON passed to the grid by my MVC6 backend. When the grid displays the date it is displayed in "2016-01-01T00:00:00". I would like to display it in for format of Jan. 01, 2016 00:00 A.M. Is this possible to do?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Formating date inside grid to Jan. 01, 2016 11:32 AM format?
« Reply #1 on: January 22, 2016, 09:33:53 pm »
Use the formatDate function of jQueryUI

https://api.jqueryui.com/datepicker/#utility-formatDate

Eagle_f90

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Formating date inside grid to Jan. 01, 2016 11:32 AM format?
« Reply #2 on: January 22, 2016, 09:46:03 pm »
How would I apply that to the column?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Formating date inside grid to Jan. 01, 2016 11:32 AM format?
« Reply #3 on: January 23, 2016, 11:51:23 am »
use column.render

Code: [Select]
column.render = function( ui ){
   var cellData = new Date( ui.cellData );
   return $.datepicker.formatDate( 'required format', cellData );
}

If you also need to format time, then datetimepicker http://trentrichardson.com/examples/timepicker/ can be used in a similar way.
« Last Edit: January 24, 2016, 05:35:27 pm by paramquery »

Eagle_f90

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Formating date inside grid to Jan. 01, 2016 11:32 AM format?
« Reply #4 on: January 25, 2016, 08:17:07 pm »
Hi, I do need to format the data but no examples from the linked site seem to work as they all work on an input box and I am not sure how to pass in the cell data for formatting. I have tried a few things but all of them break the grid. I can get the date format to work fine off the datepicker format example you gave just not the datetimepicker you linked.


Code: [Select]
            obj.colModel[9].render = function (ui)
            {
                var cellData = new Date(ui.cellData);
                return $.datetimepicker({ dateFormat: "yy-mm-dd", timeFormat: "hh:mm:ss" }, cellData);
            }

Eagle_f90

  • Newbie
  • *
  • Posts: 15
    • View Profile
Re: Formating date inside grid to Jan. 01, 2016 11:32 AM format?
« Reply #5 on: January 26, 2016, 07:42:57 pm »
Is formatting the time just not possible?