Why does it need to go inside the $tableData array? I don't think I understand the reason?
Jan 16, 2023
5
Level 3
Paginating an existing table with Livewire
I have a plain HTML table being rendered with the results of an Eloquent query.
// controller
$this->tableData['headers'] = $tableHeaders;
$this->tableData['rows'] = $query->get();
(classes, attributes and other removed for readability)
<!-- view -->
<table>
<thead>
<tr>
@foreach( $tableData['headers'] as $val )
<th>{{ $val }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach( $tableData['rows'] as $row )
<tr>
@foreach ( $row as $key => $val )
<td>{{ $val }}</td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
When I read the docs on Livewire's pagination, it seems to want paginate() called on a model of some sort.
// from the docs
public function render()
{
return view('livewire.show-posts', [
'posts' => Post::paginate(10),
]);
}
I don't really understand; if possible, how can I get this pagination feature to meet me where I'm at? If it's not possible, what would be best for me to do otherwise?
(P.S. I'm aware of the Livewire Datatables package - great package, but does not work for my specific needs due to reasons unrelated to this post)
Please or to participate in this conversation.