Render table component without a view

Is it possible to build a Filament table without a view file? Tried using Blade render but getting error:
Using $this when not in object context From inside <x-filament-tables::reorder.handle />
class ListExamples extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;

public function table(Table $table): Table
{
return $table
->query(Example::query())
->columns([
TextColumn::make('name'),
]);
}

public function render(): string
{
return Blade::render(<<<'BLADE'
<div>
{{ $table }}
</div>
BLADE, ['table' => $this->table]);
}
}
class ListExamples extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;

public function table(Table $table): Table
{
return $table
->query(Example::query())
->columns([
TextColumn::make('name'),
]);
}

public function render(): string
{
return Blade::render(<<<'BLADE'
<div>
{{ $table }}
</div>
BLADE, ['table' => $this->table]);
}
}
Solution:
You can also just return the HTML: ```php public function render() { return $this->table->toHtml();...
Jump to solution
3 Replies
Saade
Saade13mo ago
Livewire
Making Components | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Solution
Arko
Arko13mo ago
You can also just return the HTML:
public function render()
{
return $this->table->toHtml();
}
public function render()
{
return $this->table->toHtml();
}
exactwebitesolutions
Still getting the same error:
Using $this when not in object context
<x-filament::input
autocomplete="off"
inline-prefix
:placeholder="__('filament-tables::table.fields.search.placeholder')"
type="search"
:wire:model.live.debounce.500ms="$wireModel"
x-bind:id="$id('input')"
:wire:key="$this->getId() . '.table.' . $wireModel . '.field.input'"
/>
<x-filament::input
autocomplete="off"
inline-prefix
:placeholder="__('filament-tables::table.fields.search.placeholder')"
type="search"
:wire:model.live.debounce.500ms="$wireModel"
x-bind:id="$id('input')"
:wire:key="$this->getId() . '.table.' . $wireModel . '.field.input'"
/>
Rendering the table inside a modal from a form action if that makes a difference?
Select::make('example')
->suffixAction(
Action::make('table')
->icon('heroicon-o-eye')
->modalContent(fn (): HtmlString => new HtmlString(Blade::render(<<<'blade'
<livewire:list-examples />
blade)))
),
Select::make('example')
->suffixAction(
Action::make('table')
->icon('heroicon-o-eye')
->modalContent(fn (): HtmlString => new HtmlString(Blade::render(<<<'blade'
<livewire:list-examples />
blade)))
),
Want results from more Discord servers?
Add your server