MedicOneSystems / livewire-datatables

Advanced datatables using Laravel, Livewire, Tailwind CSS and Alpine JS
https://livewire-datatables.com/
MIT License
1.19k stars 258 forks source link

Automatically update one column when another is edited #569

Open bishwa3141 opened 1 year ago

bishwa3141 commented 1 year ago

I have two columns 'rate' and 'total' in my model and my Datatable has the following columns

NumberColumn::name('rate')->label('Rate)')->editable(),
NumberColumn::name('total')->label('Total')->editable(),

I need total to be automatically updated when I update the rate value. Normally I'd achieve that from my Eloquent model like this

---Model.php

protected static function boot()
    {
        parent::boot();

        self::updating(function($model){ 
            $model->total = $model->rate //(or some similar logic)
}

This works when I do a manual update of the model from my other view but when I use the Livewire datatable, the update doesn't take place on the 'total' column. Any ideas how to work around this?