livewire-datatables icon indicating copy to clipboard operation
livewire-datatables copied to clipboard

Attempt to read property "preventExport" on int

Open fmelin opened this issue 2 years ago • 6 comments

Hello guys, I have the following problem, install livewire according to the indicated steps and when showing a datatable and exporting it throws the following message:

Attempt to read property "preventExport" on int

View:

<livewire:datatable 
                        model="App\Models\User" 
                        name="all-users"
                        exclude="created_at,updated_at,id"                      
                        exportable  
                        complex="true"
                       
    />

Error Detail

  public function getExportResultsSet()

    {

        return $this->mapCallbacks(

            $this->getQuery()->when(count($this->selected), function ($query) {

                return $query->havingRaw('checkbox_attribute IN (' . implode(',', $this->selected) . ')');

            })->get(),

            true

        )->map(function ($item) {

            return collect($this->columns())->reject(function ($value, $key) {

                return $value->preventExport == true || $value->hidden == true;

            })->mapWithKeys(function ($value, $key) use ($item) {

                return [$value->label ?? $value->name => $item->{$value->name}];

            })->all();

        });

    }

more detail

https://flareapp.io/share/OmVDER87

greetings and thank you very much

fmelin avatar Jul 06 '22 02:07 fmelin

Did you manage to solve it? I have the same problem

gnumarquez avatar Jul 28 '22 20:07 gnumarquez

Looks like this is broken in the latest release. Although seems to be deeper than just the export as if you manually comment out those references it goes on to error out with issues in the hidden and name columns too.

rickmills avatar Jul 29 '22 13:07 rickmills

Same problem...

krlenix avatar Aug 04 '22 23:08 krlenix

I have same problem when using <livewire:datatables ..... />

my solution is creating datatable component first and load it into view.

han220805 avatar Aug 09 '22 06:08 han220805

i have same problem when using the data for another user but if dd all data i get

Miftahulhud2 avatar Aug 26 '22 03:08 Miftahulhud2

Found the solution

public function getExportResultsSet() { return $this->mapCallbacks( $this->getQuery()->when(count($this->selected), function ($query) { return $query->havingRaw('checkbox_attribute IN (' . implode(',', $this->selected) . ')'); })->get(), true )->map(function ($item) { return collect($this->columns)->reject(function ($value, $key) { return $value['preventExport'] == true || $value['hidden'] == true; })->mapWithKeys(function ($value, $key) use ($item) { return [$value['label'] ?? $value['name'] => $item->{$value['name']}]; })->all(); }); }

yogendrakinja avatar Oct 21 '23 19:10 yogendrakinja