sorry for the formating the code badly .. first time posting here
$data->links() generating wrong pagination url after table component is reload
Hi, i cant figured out what is wrong with my code, that $data->links() is giving me wrong pagination urls after reloading the component when setting perPage or filtering. At first when the page is loaded the urls are good and giving me /posts?page=2 but when i change rows per Page or filter in the tabl or change sorting column, the table is reloaded correctly but the pagination links became /livewire/update?post=2, here is my code:
table-component.blade.php
#pagination
{{ $data->links("pagination::simple-bootstrap-5") }}
#Search Input has-
wire:model.live.debounce.300ms="search"
#TableComponent class
use WithPagination;
public $model; // Class name of the model
public $tableHeader = [];
#
public $page;
public $perPage = 5;
public $search = '';
public $sortColumn = 'created_at';
public $sortDirection = 'desc';
public function sortBy($column)
{
if ($this->sortColumn === $column) {
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
} else {
$this->sortColumn = $column;
$this->sortDirection = 'asc';
}
}
public function updatingPerPage()
{
return $this->resetPage();
}
public function updatingSearch()
{
$this->resetPage();
}
PostTable class that extend table component
public function mount() { $this->model = Post::class; $this->tableHeader = $this->tableHeaderConfig();
}
public function delete(Post $post)
{
$post->delete();
}
public function render(Post $post)
{
$data = $post->search($this->search)
->orderBy($this->sortColumn, $this->sortDirection)
->paginate($this->perPage);
return view('livewire.example.posts-list', [
"posts" => $data
]);
}
protected function tableHeaderConfig()
{
// (column, label, sortable, liveEdit, liveEditType)
return [
["name" => Post::COL_TEXT, "display" => "Text", "sortable" => true],
["name" => Post::COL_AUTHOR_ID, "display" => "Author"],
["name" => Post::COL_CREATED_AT, "display" => "Vytvořeno", "sortable" => true],
["name" => Post::COL_UPDATED_AT, "display" => "Upraveno", "sortable" => true]
];
}
thanks for your advices..
Please or to participate in this conversation.