omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
252 stars 113 forks source link

DateTime no output in table #158

Closed evskorobogatij closed 4 years ago

evskorobogatij commented 4 years ago

I have entity Petition:

/**
 * @ApiResource
 * @ORM\Entity(repositoryClass=App\Repository\PetitionRepository::class)
 * @ORM\EntityListeners({"App\EntityListeners\PetitionListeners"})
 * @HasLifecycleCallbacks
 */
class Petition
{
    use TimestampableEntity; //adding created_at and edited_at fields
    use SoftDeleteableEntity;

    /**
     * @var UuidInterface
     * @ORM\Id
     * @ORM\Column(type="uuid")
     */
    private $id;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;

    /**
     * @ORM\Column(type="text")
     */
    private $description;

Then I try output data in table

$table = $this->createDataTable()
            ->add("name",TextColumn::class)
            ->add("description",TextColumn::class)
            ->add("created_at",DateTimeColumn::class,[
                 'format' => 'd-m-Y',
            ])
            ->add('signers',NumberColumn::class)

But no data in created_at columns/ I change:

$table = $this->createDataTable()
            ->add("name",TextColumn::class)
            ->add("description",TextColumn::class)
            ->add("created_at",DateTimeColumn::class,[
                  'render' => function(string $value,Petition $petition) {
                       $d = $petition->getCreatedAt();
                       return $d->format("Y.m.d");
                  }
            ])
            ->add('signers',NumberColumn::class)

But error occured `Uncaught Error: Call to a member function format() on null. Why data is null? It present in database table

P.S. Type of created_at is timestamp with timezone

evskorobogatij commented 4 years ago

What can i do to output DateTime (timestampz) to datatable column?

evskorobogatij commented 4 years ago

Thank youОтправлено со смартфона Samsung Galaxy. -------- Исходное сообщение --------От: Artisoy Fernandez notifications@github.com Дата: 23.06.20 17:13 (GMT+03:00) Кому: omines/datatables-bundle datatables-bundle@noreply.github.com Копия: evskorobogatij evskorobogatij@gmail.com, Author author@noreply.github.com Тема: Re: [omines/datatables-bundle] DateTime no output in table (#158) Use "createdAt" instead of "created_at". ->add("createdAt",DateTimeColumn::class,[ 'format' => 'd-m-Y', ])

—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe. [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/omines/datatables-bundle/issues/158#issuecomment-648177502", "url": "https://github.com/omines/datatables-bundle/issues/158#issuecomment-648177502", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]

curry684 commented 4 years ago

This issue can only mean there is a NULL value in your database, and your render function does not check for that.

I would recommend following the very very bad documentation at https://omines.github.io/datatables-bundle/#datetimecolumn and use the format and nullValue options to fix this issue.