You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
namespace App\Livewire\menucategory;
use App\Models\MenuCategory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Exportable;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\Rule;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
final class MenuCategoriesDataTable extends PowerGridComponent
{
public function onUpdatedToggleable(string $id, string $field, string $value): void
{
MenuCategory::query()->find($id)->update([
$field => $value,
]);
$this->skipRender();
}
public function onUpdatedEditable($id, $field, $value): void
{
MenuCategory::query()->find($id)->update([
$field => $value,
]);
}
public function setUp(): array
{
$this->showCheckBox();
return [
Exportable::make('export')
->striped()
->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV),
Header::make()->showSearchInput(),
Footer::make()
->showPerPage()
->showRecordCount(),
];
}
public function datasource(): Builder
{
return MenuCategory::query();
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('name')
->add('status')
->add('created_at')
->add('action');
}
public function columns(): array
{
return [
Column::make('Name', 'name')
->searchable()
->sortable()->editOnClick(true),
Column::make('Status', 'status')
->searchable()
->sortable()->toggleable(true, 'Yes', 'No'),
Column::make('Created at', 'created_at'),
Column::action('Action', 'action')
];
}
/*
public function filters(): array
{
return [
Filter::inputText('name'),
Filter::datepicker('created_at_formatted', 'created_at'),
];
}
#[\Livewire\Attributes\On('edit')]
public function edit($rowId): void
{
$this->js('alert('.$rowId.')');
}
public function actions(MenuCategory $row): array
{
return [
Button::add('edit')
->slot('Edit: '.$row->id)
->id()
->class('pg-btn-white dark:ring-pg-primary-600 dark:border-pg-primary-600 dark:hover:bg-pg-primary-700 dark:ring-offset-pg-primary-800 dark:text-pg-primary-300 dark:bg-pg-primary-700')
->dispatch('edit', ['rowId' => $row->id])
];
}
public function actionRules(MenuCategory $row): array
{
return [
// Hide button edit for ID 1
Rule::button('edit')
->when(fn($row) => $row->id === 1)
->hide(),
];
}
*/
}
I have made name column as editable and status button as toggleable, but when I do this, name column is there but there not values in column and can not edit or see current values,
Also all toggle are in OFF mode only, I have values Yes and No in database, Also while changing toggle, it does not fire update method,
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I have below code,
I have made
name
column as editable and status button as toggleable, but when I do this, name column is there but there not values in column and can not edit or see current values,Also all toggle are in OFF mode only, I have values
Yes
andNo
in database, Also while changing toggle, it does not fire update method,I am using bootstrap CSS,
What's wrong? See below screenshot,
Beta Was this translation helpful? Give feedback.
All reactions