hjalmers / angular-generic-table

A generic table for Angular 2+. Generic table uses standard markup for tables ie. table, tr and td elements etc. and has support for expanding rows, global search, filters, sorting, pagination, export to CSV, column clicks, custom column rendering, custom export values.
https://hjalmers.github.io/angular-generic-table/
MIT License
105 stars 55 forks source link

How to format the date in data grid ? #192

Open Syedgit opened 6 years ago

Syedgit commented 6 years ago

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;
    }
Crash1988 commented 6 years ago

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

sahilkatia commented 6 years ago

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

hjalmers commented 6 years ago

@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?