Kyslik / column-sortable

Package for handling column sorting in Laravel 5/6/7/8
MIT License
639 stars 105 forks source link

Livewire & Column Sortable #176

Open kevintresuelo opened 3 years ago

kevintresuelo commented 3 years ago

Hi! I've ran into an issue when @sortablelink() is placed inside a livewire component. When livewire updates its components, the link of the sortable also changes, which is replaced by some sort of fingerprint. Following code produces the error:

livewire table, using Livewire/WithPagination:

<div>
  <table>
    <thead>
      <tr>
        <th>
          @sortablelink('name', 'Name')
        </th>
      </tr>
    </thead>
    <tbody>
      @foreach($users as $user)
        <tr>...</tr>
      @endforeach
    </tbody>
  </table>
  {{ $users->links() }}
</div>

When the page first loads, the URL of the heading points to

http://localhost/users?sort=name&direction=asc

but after switching pages using Livewire's pagination, it now points to

http://localhost/livewire/message/users.users-table?fingerprint%5Bid%5D=v6Zb7qW4xmXvLXU0kghM&fingerprint%5Bname%5D=users.users-table&fingerprint%5Blocale%5D=en&fingerprint%5Bpath%5D=users&fingerprint%5Bmethod%5D=GET&serverMemo%5BhtmlHash%5D=9484b845&serverMemo%5Bdata%5D%5Bsort%5D=name&serverMemo%5Bdata%5D%5Bdirection%5D=desc&serverMemo%5Bdata%5D%5Bpage%5D=2&serverMemo%5Bchecksum%5D=1b6b1aeb0105128d0ff7a96a3f5071f5f72baaec04d7b18a49d7333f5ee415ef&updates%5B0%5D%5Btype%5D=callMethod&updates%5B0%5D%5Bpayload%5D%5Bmethod%5D=nextPage&sort=name&direction=asc
Kyslik commented 3 years ago

I am not familiar with livewire; perhaps it uses some JS to manipulate DOM? I don't think I can help here.

DanielSpindler commented 2 years ago

hey @kevintresuelo ive ran into the same issue, do you by any chance remember how you fixxed it?

Healyhatman commented 2 years ago

Best bet is probably to specify the href attribute

DanielSpindler commented 2 years ago

i just made it so that clicking the Sort redirects to the first page of the Table. Solved one of the Problems. (Who would want to sort midways anyway) thanks for the Suggestion @Healyhatman

Shaka-60hp commented 2 years ago

i just made it so that clicking the Sort redirects to the first page of the Table. Solved one of the Problems. (Who would want to sort midways anyway) thanks for the Suggestion @Healyhatman

How? could you post the solution as an example? ... Thanks

Uryon987 commented 1 year ago

Got same issue, if anyone found a solution please give us a feedback :)