angular-generic-table icon indicating copy to clipboard operation
angular-generic-table copied to clipboard

How to format the date in data grid ?

Open Syedgit opened this issue 8 years ago • 3 comments

How to format date in generic table below native javascript approach is not working ?


format i am getting from backend '1506530292'
{
          name:'Ticket Opened',
          objectKey:'ticketOpened',
          render: function(row){ this.formatDate(row.ticketOpened)},
}

   formatDate(date) {
      var monthNames = [
        "January", "February", "March",
        "April", "May", "June", "July",
        "August", "September", "October",
        "November", "December"
      ];

      var day = date.getDate();
      var monthIndex = date.getMonth();
      var year = date.getFullYear();

      return day + ' ' + monthNames[monthIndex] + ' ' + year;
    }

Syedgit avatar Jan 31 '18 17:01 Syedgit

hi @Syedgit, i suggest you to use a Pipe instead, it worked for me this approach, constructor(private datePipe: DatePipe) and then in the configObject.fields you could have something like this:

{  name: 'DATE',
       objectKey: 'accountDate',
       render: (row) => {
          if (row.accountDate != null)
              return this.datePipe.transform(row.accountDate, 'MM/dd/yyyy');
           return ''
       },
},

i hope this works for you, greetings

Crash1988 avatar Feb 05 '18 15:02 Crash1988

Any Date picker using this table? or any option to select the date?

sahilkatia avatar Feb 08 '18 21:02 sahilkatia

@sahilkatia perhaps you could elaborate a little on what you want to do? If you want to be able to select a date you could look at using a custom component, perhaps together with this datepicker?

hjalmers avatar Feb 09 '18 09:02 hjalmers