Power-Components / livewire-powergrid

⚡ PowerGrid generates modern, powerful and easy-to-customize data tables using Laravel Livewire.
https://livewire-powergrid.com
MIT License
1.41k stars 206 forks source link

Filter::select with sortby not working #1586

Open eafarooqi opened 3 weeks ago

eafarooqi commented 3 weeks ago

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; })

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
 //...