Power-Components / livewire-powergrid

⚡ PowerGrid generates modern, powerful and easy-to-customize data tables using Laravel Livewire.

Home Page:https://livewire-powergrid.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filter::select with sortby not working

eafarooqi opened this issue · comments

Have you searched through other issues to see if your problem is already reported or has been fixed?

Yes, I did not find it.

Did you read the documentation?

Yes, I did not find it.

Have you tried to publish the views?

Yes - I didn't work.

Is there an error in the console?

No

PHP Version

8.2

PowerGrid

4.9.8

Laravel

10.48.12

Livewire

2.12.6

Alpine JS

3.14.0

Theme

Bootstrap

Describe the bug.

When using select filter data source as a sorted collection we get the following error after search
Livewire encountered corrupt data when trying to hydrate the component. Ensure that the [name, id, data] of the Livewire component wasn't tampered with between requests.

To Reproduce...

This code produce error after selecting some value from the dropdown

Filter::select('contract_type_id', 'contract_type_id') ->dataSource(ContractType::all()->sortBy('name')) ->optionValue('id') ->optionLabel('name'),
Error:
Livewire encountered corrupt data when trying to hydrate the component. Ensure that the [name, id, data] of the Livewire component wasn't tampered with between requests.

This works fine without the sortBy

Filter::select('contract_type_id', 'contract_type_id') ->dataSource(ContractType::all()) ->optionValue('id') ->optionLabel('name')

This is how columns are setup
->addColumn('contract_type_id', function (Offer $offer) { return $offer->contractType->name; })

  • contractType is a BelongsTo relation on model

columns function
Column::make('Type', 'contract_type_id')->sortable(),

data source:
public function datasource(): Builder|Offer { // query to get data return Offer::query()->with(['contractType']); }

The table is very simple with just two columns
id: primary key auto increment
name: varchar

Extra information

<?php
 //...