livewire-datatables icon indicating copy to clipboard operation
livewire-datatables copied to clipboard

Column::callback(): Argument #1 ($columns) must be of type string, array given

Open code23-barna opened this issue 2 years ago • 5 comments

In src/Column.php:118 you set the type to "string" when it should be Array|String

Raised a PR to fix it: https://github.com/MedicOneSystems/livewire-datatables/pull/428

code23-barna avatar Mar 23 '22 17:03 code23-barna

The problem with this merge is, that's it's not working with PHP 7 anymore.

Lirux avatar Mar 29 '22 14:03 Lirux

Sure that PHP7 is not able to do type hint?

thyseus avatar Mar 29 '22 14:03 thyseus

I think not. Am I correct? https://www.php.net/manual/de/language.types.declarations.php#language.types.declarations.composite.union

Lirux avatar Mar 29 '22 15:03 Lirux

Could be a solution to drop the type declarations?

code23-barna avatar Mar 30 '22 07:03 code23-barna

I had this same issue, I was using a string to make the names unique. I changed the string to a dummy array value. Seems like a better solution would be to use the label with generating the internal callback name.

            Column::callback(['aqua_camp_weeks.id'], function($id) {
                return ('<a href="'. route('add-camper-to-session', ["id" => $id]) .'" 
                class="p-1 text-blue-600 hover:bg-blue-600 hover:text-white rounded">
                Add Child </a>');
            }**,['a']**) //array ['a'] at end is required since the callback is id all the callback functions have the same name
            ->label('Add Child')
            ->unsortable()
            ->excludeFromExport(),
            Column::callback(['aqua_camp_weeks.id'], function($id) {
                    return $this->weekStatus[$id];
                },**['b']**)
                ->unsortable()
                ->label('Week Status'),

gabepettus avatar Apr 28 '22 15:04 gabepettus