contributte / datagrid

:muscle: DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc
https://contributte.org/packages/contributte/datagrid/
MIT License
285 stars 189 forks source link

DateTimeZone #1063

Open ne2d opened 1 year ago

ne2d commented 1 year ago

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'));

mskocik commented 1 year ago

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');
  });
jspetrak commented 4 weeks ago

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