'outside']); } public function setUp(): array { $this->showCheckBox(); return [ PowerGrid::exportable(fileName: 'song-file') ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV), PowerGrid::header() ->showSoftDeletes() ->showToggleColumns() ->showSearchInput(), PowerGrid::footer() ->showPerPage() ->showRecordCount(), ]; } public function header(): array { return [ Button::add('bulk-delete') ->slot('Bulk delete ()') ->icon('solid-trash',['id' => 'my-custom-icon-id', 'class' => 'font-bold']) ->class('inline-flex items-center gap-1 px-3 py-1 rounded ') ->dispatch('bulkDelete.' . $this->tableName, []), ]; } public function datasource(): Builder { return Song::query()->with([ 'language:id,name', 'artists:id,name' ]); } public function relationSearch(): array { return []; } public function fields(): PowerGridFields { return PowerGrid::fields() ->add('id') ->add('name') ->add('simplified') ->add('phonetic_abbr') ->add('pinyin_abbr') ->add('filename') ->add('adddate_formatted', fn (Song $model) => Carbon::parse($model->adddate)->format('Y-m-d')) ->add('song_artists' ,fn(Song $model)=> $model->str_artists()) ->add('language_type', fn (Song $model) => optional($model->language)->name) ->add('song_categories', fn(Song $model) => $model->str_categories()) ->add('db_change') ->add('vocal') ->add('situation') ->add('copyright01') ->add('copyright02') ->add('note01') ->add('note02') ->add('note03') ->add('note04') ->add('enable', fn ($item) => $item->enable ? '✅' : '❌') ->add('unnamed_21') ->add('created_at_formatted', fn (Song $model) => Carbon::parse($model->created_at)->format('Y-m-d H:i:s')); } public function columns(): array { return [ Column::make(__('songs.id'), 'id'), Column::make(__('songs.name'), 'name') ->sortable() ->searchable(), Column::make(__('songs.simplified'), 'simplified') ->sortable() ->searchable() ->hidden(true, false), Column::make(__('songs.name.phinetic'), 'phonetic_abbr') ->sortable() ->searchable() ->hidden(true, false), Column::make(__('songs.name.pinyin'), 'pinyin_abbr') ->sortable() ->searchable() ->hidden(true, false), Column::make(__('songs.filename'), 'filename') ->sortable() ->searchable(), Column::make(__('songs.adddate'), 'adddate_formatted', 'adddate') ->sortable(), //歌手 Column::make(__('songs.artists'), 'song_artists'), Column::make(__('songs.language_type'),'language_type', 'language.name') ->searchable(), //分類 Column::make(__('songs.categorys'), 'song_categories'), //點播次數 Column::make('Db change', 'db_change'), Column::make(__('songs.vocal'), 'vocal'), Column::make(__('songs.situation'), 'situation') ->sortable() ->searchable(), Column::make(__('songs.copyright01'), 'copyright01') ->sortable() ->searchable(), Column::make(__('songs.copyright02'), 'copyright02') ->sortable() ->searchable() ->hidden(true, false), Column::make(__('songs.note01'), 'note01') ->sortable() ->searchable(), Column::make(__('songs.note02'), 'note02') ->sortable() ->searchable(), Column::make(__('songs.note03'), 'note03') ->sortable() ->searchable() ->hidden(true, false), Column::make(__('songs.note04'), 'note04') ->sortable() ->searchable() ->hidden(true, false), Column::make(__('songs.enable'), 'enable'), Column::make('Unnamed 21', 'unnamed_21') ->sortable() ->searchable() ->hidden(true, false), Column::make('Created at', 'created_at_formatted', 'created_at') ->sortable(), Column::action(__('songs.actions')) ]; } public function filters(): array { return [ Filter::inputText('name')->placeholder(__('songs.name')), Filter::inputText('phonetic_abbr')->placeholder(__('songs.name.phinetic')), Filter::inputText('pinyin_abbr')->placeholder(__('songs.name.pinyin_abbr')), Filter::inputText('filename')->placeholder(__('songs.filename')), Filter::datepicker('adddate'), Filter::select('language_type', 'language_type') ->dataSource(SongLanguage::all()) ->optionValue('id') ->optionLabel('name'), Filter::inputText('copyright01')->placeholder(__('songs.copyright01')), Filter::inputText('copyright02')->placeholder(__('songs.copyright02')), Filter::inputText('note01')->placeholder(__('songs.note01')), Filter::inputText('note02')->placeholder(__('songs.note02')), Filter::inputText('note03')->placeholder(__('songs.note03')), Filter::inputText('note04')->placeholder(__('songs.note04')), Filter::boolean('enable')->label('✅', '❌'), Filter::datetimepicker('created_at'), ]; } #[On('bulkDelete.{tableName}')] public function bulkDelete(): void { $this->js('alert(window.pgBulkActions.get(\'' . $this->tableName . '\'))'); if($this->checkboxValues){ Artist::destroy($this->checkboxValues); $this->js('window.pgBulkActions.clearAll()'); // clear the count on the interface. } } public function actions(Song $row): array { return [ Button::add('edit') ->slot(__('songs.edit')) ->icon('solid-pencil-square') ->class('inline-flex items-center gap-1 px-3 py-1 rounded ') ->dispatchTo('admin.song-form', 'openEditSongModal', ['id' => $row->id]), Button::add('delete') ->slot(__('songs.delete')) ->icon('solid-trash') ->class('inline-flex items-center gap-1 px-3 py-1 rounded ') ->dispatchTo('admin.song-form', 'deleteSong', ['id' => $row->id]), ]; } /* public function actionRules($row): array { return [ // Hide button edit for ID 1 Rule::button('edit') ->when(fn($row) => $row->id === 1) ->hide(), ]; } */ }