rappasoft / laravel-livewire-tables

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

Rows not removed after filtering #378

Closed SPQRBrutus closed 3 years ago

SPQRBrutus commented 3 years ago

When I have 10 records and for example 3 after filtering only 3 rows are rendered and other 7 stay thare.

image

rappasoft commented 3 years ago

Please post the code to your table and any other relevant information.

SPQRBrutus commented 3 years ago

It's nothing special.

<?php

namespace App\Http\Livewire\Frontend\Client;

use App\Domains\Client\Models\Klient;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filter;

class ClientsTable extends DataTableComponent
{
    /**
     * @return Builder
     */
    public function query(): Builder
    {
        return Klient::select("klient_id", "knazov", "kmesto", "ktyp", "kobchodnik", "kschvalenie", "kico")
            ->where("zruseny", "<>", 1)
            ->when($this->getFilter('type'), fn ($query, $type) => $query->where('ktyp', $type))
            ->when($this->getFilter('owned'), function ($query, $owned) {
                if ($owned == 1) {
                    $query->where("kobchodnik", "AdminIstrator");
                } elseif ($owned == 2) {
                    $query->where(function ($query) {
                        $query->where("kobchodnik", "")->orWhere("kobchodnik", null);
                    });
                }
            });
    }

    public function filters(): array
    {
        return [
            'type' => Filter::make('Type')
            ->select([
                '' => 'Everything',
                Klient::TYPE_AGENCY => 'Agency',
                Klient::TYPE_CLIENT => 'Client',
            ]),

            'owned' => Filter::make('Salesperson')
            ->select([
                '' => 'Everything',
                1 => 'Owned',
                2 => 'Without Salesperson',
            ]),
        ];
    }

    /**
     * @return array
     */
    public function columns(): array
    {
        return [
            Column::make(__('Title'), 'knazov')
                ->sortable()
                ->searchable(),
            Column::make(__('City'), 'kmesto')
                ->searchable()
                ->sortable(),
            Column::make(__('Status'), 'kschvalenie')
                ->sortable(),
            Column::make(__('Type'), 'ktyp')
                ->sortable(),
            Column::make(__('Salesperson'), 'kobchodnik')
                ->searchable()
                ->sortable(),
            Column::make(__('Actions'))
                ->format(function ($value, $column, $row) {
                    return view('frontend.client.includes.actions', ['client' => $row]);
                }),
            Column::make(__('Links'))
                ->format(function ($value, $column, $row) {
                    return view('frontend.client.includes.links', ['client' => $row]);
                }),
        ];
    }
}

View:

@section('content')
    <x-backend.card>
        <x-slot name="body">
            <livewire:frontend.client.clients-table />
        </x-slot>
    </x-backend.card>
@endsection

Laravel version: 8.24 Livewire version: 2.0 Datatables version: 1.10.4

rappasoft commented 3 years ago

Looks fine from here. Hard to say without the whole project. Feel free to e-mail me the project and I'll install and try to see if it's a bug or not.

SPQRBrutus commented 3 years ago

Looks fine from here. Hard to say without the whole project. Feel free to e-mail me the project and I'll install and try to see if it's a bug or not.

Can't do this. It's basically raw installation of yours laravel boilerplate only with updated Livewire datatables and SQLAnywhere database module.

rappasoft commented 3 years ago

I don't see anything glaring. Here is an example with filters working and the gist behind it. Maybe someone else can take a look.

It looks like a dom-diff issue but it's hard to say why because the table looks pretty basic.

SPQRBrutus commented 3 years ago

Found the problem. My database table had different primary key then ID. After change

public string $primaryKey = 'klient_id';

it's starts working.

Thanks for help