rappasoft / laravel-livewire-tables

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

Table does refresh when perPage changed and displaying various amount of rows #259

Closed R00118189 closed 3 years ago

R00118189 commented 3 years ago

noticed it when upgraded from 1.2.2 to 1.4.0

It is weird behaviour and the best to illustrate with the video. LivewireTablesPagination You can notice some of the rows are not updated some are added to DOM maybe it is a livewire recent update and not the package or package custom pagination classes.

Edit: I created simple Livewire component used withPagination and it worked as intended. So I suspect something is within the package which renders the table in a weird way.

rappasoft commented 3 years ago

If you have published the views, delete them and see if it makes a difference. Otherwise drop your component code here.

R00118189 commented 3 years ago

Deleted vendor file in resources as well as the main vendor then composer install and run both tailwind and bootstrap "themes" still the same result, component as basic as it can be

<?php

namespace App\Http\Livewire;

use App\Models\Item;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;

class Index extends DataTableComponent
{
    public function query() : Builder
    {
        return Item::query();
    }

    public function columns() : array
    {
        return [
            Column::make('Column 1', 'column_1')->format(fn ($value) => Str::limit($value, 15)),
            Column::make('Column 2', 'column_2'),
            Column::make('Column 3', 'column_3'),
            Column::make('Column 4', 'column_4'),
        ];
    }
}

vendordeleted

Edit: if you look at pagination the correct amount of rows is returned, but more rows are rendered in the loop.

rappasoft commented 3 years ago

Try clearing the session or trying in incognito mode and see if it makes a difference.

R00118189 commented 3 years ago

All done as instructed used checked chrome, safari and firefox incognito modes problem persists. I want to add that the count is correct if searching, but the table renders some residual data. it almost looks like this part causes some form of view "caching."

   @forelse ($rows as $index => $row)
       <x-livewire-tables::table.row
         ...
      </x-livewire-tables::table.row>
   @empty

if component <x-livewire-tables::table.row> is replaced with pure data $row

   @forelse ($rows as $index => $row)
      {{ $row }}
   @empty

it renders fine and is not "caching" the view

I suspect it may be Id field I am using UUID on the models

rappasoft commented 3 years ago

Hmm ok. Give me everything you can in order to recreate this, whether it be the full project if possible. Otherwise the whole component, model, and maybe a seeder. I'll figure it out.

R00118189 commented 3 years ago

Yes, it was the UUID on the model. I did not add my uuids trait to this model. so autoincrement was not set to false and key to string

 public function getIncrementing()
    {
        return false;
    }

public function getKeyType()
    {
        return 'string';
    }

id field was returning 0 or if UUID value was starting with digits only those starting digits were returned. I only found out when printed {{$row}} in the loop. so the id field was messing with the loop.

apologies, I think we can close this issue, however if you wish to recreate this use model with UUID but without the trait

rappasoft commented 3 years ago

Haha ok, I think that is super-specific and this package isn't big enough yet probably for someone else to run into it. Maybe I'll add a note to the primary key docs about it just in case. Good find though.