rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.78k stars 337 forks source link

setTdAttributes row has null id #752

Closed michele-grifa closed 2 years ago

michele-grifa commented 2 years ago

I'm using setTdAttributes method to add some classes to the cells and i also need to access the row to take the id, but for some reason the id is always null.

The Model Class

class Anagrafica extends Model
{
    use HasFactory;

    protected $table = "anagrafiche";

    public $timestamps = true;
    protected $primaryKey = 'id';

    protected $visible = [];

    protected $hidden = [];
    ...
}

The DataTable Class

$this->setTdAttributes(function(Column $column, $row, $columnIndex, $rowIndex) {
            if($column->isField('codice')) {
                return [
                    'default' => true,
                    'class' => 'some-class',
                    'wire:click' => "\$emit('showModal', 'test-modal', " . $row->id . ")"
                ];
            }
            else {
                return [
                    'default' => true,
                    'class' => 'some-class'
                ];
            }
        });

Laravel Version: 8.83.10 Laravel Livewire Tables Version: 2.4.0

rappasoft commented 2 years ago

Is the column selected? By default you only have properties available to the columns you have specified. If you want more you have to add them with setAdditionalSelects

michele-grifa commented 2 years ago

Thanks, i used that method and it worked.