datagrid icon indicating copy to clipboard operation
datagrid copied to clipboard

DateTimeZone

Open ne2d opened this issue 2 years ago • 2 comments
trafficstars

https://github.com/contributte/datagrid/blob/1b0ff6a229d471df21ef7a64132f9ebe76a8d947/src/Column/ColumnDateTime.php#L35

It's possible to set up here timezone? Something like this? $date->setTimezone(new \DateTimeZone('Europe/Prague'));

ne2d avatar Jan 24 '23 13:01 ne2d

You can set it in custom renderer through setRenderer, although it renders usage of ColumnDateTime useless and you can use ColumnText instead. Something like this:

$tz = new \DateTimeZone('Europe/Prague');
$grid->setColumnText('date', 'Date') // of course you can call `addColumnDateTime`
  ->setRenderer(function($item) use ($tz) {
    $date = $item->dateProp;
    $date->setTimezone($tz);
    return $date->format('Y-m-d');
  });

mskocik avatar Jun 13 '23 07:06 mskocik

@mskocik

although it renders usage of ColumnDateTime useless

If I keep using ColumnDateTime and use the custom renderer, does the column retain capability to sort by datetime values?

Edit ex post

Yes.

jspetrak avatar Jun 07 '24 21:06 jspetrak