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
This is my code. I have included the withSum on the total column but it doesn't preview in my browser. I'm using tailwind
`<?php
namespace App\Livewire;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\Exportable;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
final class StockTable extends PowerGridComponent
{
public $mydata;
public $nettotal = 0;
public function mount(): void
{
parent::mount();
$this->mydata = collect($this->mydata);
}
public function datasource(): ?Collection
{
return $this->mydata;
}
public function setUp(): array
{
return [
Header::make()->showSearchInput(),
Footer::make()
->showPerPage()
->showRecordCount()
->includeViewOnBottom('components.datatable.button'),
];
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('name')
->add('quantity')
->add('costprice')
->add('sellingprice')
->add('total');
}
public function columns(): array
{
return [
Column::make('ID', 'id')
->searchable()
->sortable(),
Column::make('Name', 'name')
->searchable()
->sortable(),
Column::make('Quantity', 'quantity')
->searchable()
->sortable(),
Column::make('Cost price', 'costprice')
->sortable(),
Column::make('Selling price', 'sellingprice')
->sortable(),
Column::make('Total', 'total')
->sortable()
->withSum('Total',true,true),
Column::action('Action')
];
}
protected function getListeners()
{
return array_merge(
parent::getListeners(),
[
'addDrug'
]
);
}
public function myaction($id){
$this->mydata = $this->mydata->reject(function ($item) use($id){
return $item['id'] == $id;
});
// recalculate net total
$this->nettotal = $this->mydata->sum('total');
$this->dispatch('pg:eventRefresh-default');
}
public function actions(): array
{
return
[
Button::add('delete')
->render(function($mydata){
return Blade::render(<<<HTML
<i class="bi bi-trash-fill text-red-600" wire:click="myaction('$mydata->id')"></i>
HTML);
}),
];
}
public function addDrug($data){
// check if drug exists
if(empty($this->mydata->firstWhere('fullname',$data['fullname']))){
$this->mydata->push($data);
$this->nettotal += $data['total'];
}
}
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
-
This is my code. I have included the withSum on the total column but it doesn't preview in my browser. I'm using tailwind
`<?php
namespace App\Livewire;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;
use PowerComponents\LivewirePowerGrid\Button;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\Exportable;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
final class StockTable extends PowerGridComponent
{
public $mydata;
public $nettotal = 0;
public function mount(): void
{
parent::mount();
$this->mydata = collect($this->mydata);
}
public function datasource(): ?Collection
{
return $this->mydata;
}
}
`
Beta Was this translation helpful? Give feedback.
All reactions