livewire-powergrid
livewire-powergrid copied to clipboard
Exporting only one record
trafficstars
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.3
PowerGrid
v5.10.5
Laravel
10.3
Livewire
3.5.6
Alpine JS
No response
Theme
Tailwind 3.x
Describe the bug.
I cant export more than one record. Even selecting all
To Reproduce...
Just select more then 2 records
Extra information
<?php
<?php
namespace App\Livewire\Dashboard\Admin\Assessment\Assessment;
use App\Actions\Helper\ReportRoundNumber;
use App\Models\AssessmentAnswer;
use App\Models\AssessmentCompetency;
use App\Models\AssessmentQuestion;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Livewire\Attributes\Url;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Exportable;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Traits\WithExport;
final class AssessmentValidatorTable extends PowerGridComponent
{
use WithExport;
#[Url]
public $ids;
public string $sortField = 'user_type';
public $answer;
public function setUp(): array
{
$this->showCheckBox();
return [
Exportable::make('validador-da-dados')
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV),
Header::make()->showSearchInput(),
Footer::make()
->showPerPage(50)
->showRecordCount(mode: 'full'),
];
}
public function datasource(): Builder
{
$answers = AssessmentAnswer::query()
->whereNa(false)
->when($this->ids, function ($query) {
return $query->whereIn('assessment_evaluated_id', $this->ids);
})
->leftJoin('assessment_questions', function ($user) {
$user->on('assessment_questions.id', '=', 'assessment_answers.assessment_question_id');
})
->leftJoin('assessment_competencies', function ($user) {
$user->on('assessment_competencies.id', '=', 'assessment_answers.assessment_competency_id');
})
->select([
'assessment_answers.id',
'assessment_answers.user_type',
'assessment_answers.points',
'assessment_answers.assessment_quizz_id',
'assessment_questions.id as question_id',
'assessment_questions.title as question_name',
'assessment_competencies.id as competency_id',
'assessment_competencies.title as competency_name',
]);
$this->answer = $answers->first();
return $answers;
}
public function relationSearch(): array
{
return [];
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('user_type_text')
->add('user_name')
->add('competency_name', function (AssessmentAnswer $model) {
return $model->competency_name;
})
->add('question_name', function (AssessmentAnswer $model) {
return Str::limit($model->question_name, 40, '...');
})
->add('commentary')
->add('points')
->add('na')
->add('created_at');
}
public function columns(): array
{
return [
Column::make('Tipo', 'user_type_text'),
Column::make('Competência', 'competency_name'),
Column::make('Pergunta', 'question_name'),
Column::make('Nota', 'points')
->withAvg('Média', header: true, footer: false),
];
}
public function filters(): array
{
return [
Filter::select('question_name', 'assessment_question_id')
->dataSource(AssessmentQuestion::where('quizz_id', $this->answer->assessment_quizz_id)->get())
->optionLabel('title')
->optionValue('id'),
Filter::select('user_type_text', 'user_type')
->dataSource([['name' => 'Autoavaliação', 'id' => 0],
['name' => 'Líder / Sócio', 'id' => 1],
['name' => 'Liderado(a)', 'id' => 2],
['name' => 'Par / Outro', 'id' => 3]
])
->optionLabel('name')
->optionValue('id'),
Filter::select('competency_name', 'assessment_competency_id')
->dataSource(AssessmentCompetency::where('quizz_id', $this->answer->assessment_quizz_id)->get())
->optionLabel('title')
->optionValue('id'),
];
}
public function summarizeFormat(): array
{
return [
'points.{avg}' => fn ($value) => ReportRoundNumber::run($value),
];
}
}
//...
When i try to export only SELECTED and not ALL records, i've provoked an error and i could see this in the end: LIMIT 1
I don't know if this persists in version 6.x because the base underwent a huge structure change. For now, I'll close this and look into it.
Thank you