Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from thejoeejoee/fix/csv-birthday-export
Browse files Browse the repository at this point in the history
Fixed CSV export of birthday date
  • Loading branch information
thanhdolong authored Oct 18, 2020
2 parents ab307dc + 92f8502 commit d89b56e
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions app/Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Grid;

use Nette\Database\Context;
use Nette\Database\Table\ActiveRow;
use Nette\Utils\DateTime;
use Ublaboo\DataGrid\Column\ColumnText;
use Ublaboo\DataGrid\DataGrid;

Expand Down Expand Up @@ -82,27 +84,35 @@ function showFaculty($faculties)

function showExportCsv()
{
$column_name = new ColumnText($this, 'name', 'data_user.name', 'Name');
$column_surname = (new ColumnText($this, 'surname', 'data_user.surname', 'Surname'));
$column_birthday = (new ColumnText($this, 'birthday', 'data_user.birthday', 'Birthday'));
$column_country = (new ColumnText($this, 'country', 'data_user.country_id', 'Country'));
$column_email = (new ColumnText($this, 'email', 'user.user_id', 'Email'));
$column_registered = (new ColumnText($this, 'registered', 'data_user.registered', 'Registered'));

$name = new ColumnText($this, 'name', 'data_user.name', 'Name');
$surname = (new ColumnText($this, 'surname', 'data_user.surname', 'Surname'));
$birthday = (new ColumnText($this, 'birthday', 'data_user.birthday', 'Birthday'));
$country = (new ColumnText($this, 'country', 'data_user.country_id', 'Country'));
$email = (new ColumnText($this, 'email', 'user.user_id', 'Email'));
$registered = (new ColumnText($this, 'registered', 'data_user.registered', 'Registered'));

$birthday->setRenderer(function (ActiveRow $row) {
/** @var DateTime|NULL $value */
$value = $row->ref('data_user')->birthday;
if (!$value) return '';

$date = $value->format('Y-m-d');
return $date != '1970-01-01' ? $date : NULL;
});

$this->addExportCsvFiltered('Csv export', "fiesta.csv", "UTF-8", ";", true)
->setTitle('Csv export')
->setColumns([
$column_name,
$column_surname,
$column_birthday,
$column_email,
$column_country,
$column_registered
$name,
$surname,
$birthday,
$email,
$country,
$registered
]);
}

function showEditableStatus(callable $onSuccess)
public function showEditableStatus(callable $onSuccess)
{

$this->addColumnStatus('status', 'Status', "user.status:data_user")
Expand Down

0 comments on commit d89b56e

Please sign in to comment.