livewire / flux

The official Livewire UI component library
https://fluxui.dev
476 stars 42 forks source link

Flux Table Pagination Error #470

Closed kemdo25 closed 3 weeks ago

kemdo25 commented 3 weeks ago

Hi there! 👋

flux table pagination issue: if i remove pagination and loading data normally it working i got message livewire component not supported, i tried either way to fix out but not working Property type not supported in Livewire for property: [{"current_page":1,"data":[{"id":1,"tax_identification_number":"135202665","certificate_number":"167610021","company_name":"King Charcoal Africa if it concern: among fields i have json which hold very large object

my livewire property:

          #[Computed]
              public function getCompanies()
              {
                  $query = OilCompany::query();
                  if ($this->sortBy) {
                      $query->orderBy($this->sortBy, $this->sortDirection);
                  }
                  $this->companies = $query->paginate(5);
              }

flux table component:

   <flux:table :paginate="$this->companies" >
                                  <flux:columns>
                                      .....
                                  </flux:columns>

                                  <flux:rows>

                                      @foreach ($this->companies as $c)
                                          <flux:row>
                                             ...

                                          </flux:row>
                                      @endforeach

                                  </flux:rows>
           </flux:table>

my livewire component called within laravel view:

<x-app-layout title="Company Registration" is-sidebar-open="true" is-header-blur="true">
    @livewire('registration.reg-company-wire');
</x-app-layout>
jeffchown commented 3 weeks ago

@kemdo25 Have you tried removing your property's companies property, renaming the computed property to companies() (to replace the removed property) and returning the paginated collection directly from the computed property's method?:

#[Computed]
public function companies()
{
    $query = OilCompany::query();
    if ($this->sortBy) {
        $query->orderBy($this->sortBy, $this->sortDirection);
    }
    return $query->paginate(5);
}
calebporzio commented 3 weeks ago

Thanks @jeffchown, that's the right answer, closing this.

jeffchown commented 3 weeks ago

You're welcome, @calebporzio

kemdo25 commented 3 weeks ago

thanks so much its working