Kreyu / data-table-bundle

Streamlines creation process of the data tables in Symfony applications. NOT PRODUCTION READY.
https://data-table-bundle.swroblewski.pl
MIT License
75 stars 14 forks source link

Improve integration with Profiler, actions & collection column types #130

Closed Kreyu closed 1 month ago

Kreyu commented 1 month ago
nicodemuz commented 1 month ago

I can't seem to use CollectionColumnType:

            ->addColumn('rifeProgramFrequencies', CollectionColumnType::class, [
                'entry_options' => [
                    'formatter' => function (RifeProgramFrequency $rifeProgramFrequency): string {
                        return $rifeProgramFrequency->getFrequency();
                    },
                ],
            ])

image

Kreyu commented 1 month ago

I can't seem to use CollectionColumnType:

            ->addColumn('rifeProgramFrequencies', CollectionColumnType::class, [
                'entry_options' => [
                    'formatter' => function (RifeProgramFrequency $rifeProgramFrequency): string {
                        return $rifeProgramFrequency->getFrequency();
                    },
                ],
            ])

Hey @nicodemuz, try setting a property path inside the entry_options that will direct the bundle on which property should be displayed:

 ->addColumn('rifeProgramFrequencies', CollectionColumnType::class, [
     'entry_options' => [
         'property_path' => 'frequency',
     ],
 ])

Because the CollectionColumnType creates "fake" columns inside itself for each entry in the collection, the property path will default to column name, which in this case would be 0, 1, 2, etc. (index of each entry).

The formatter callback is applied on the data retrieved from the entity, so it's later in the process. Alternatively, you can use the getter instead of property path:

 ->addColumn('rifeProgramFrequencies', CollectionColumnType::class, [
     'entry_options' => [
         'getter' => function (RifeProgramFrequency $rifeProgramFrequency): string {
             return $rifeProgramFrequency->getFrequency();
         },
     ],
 ])